LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic number of channels in TDMS

Solved!
Go to solution

Hey guys,

 

I will try to explain what I want to achieve. I measure different gas concentrations and store them in TDMS. During one measurement session, the number of gases can increase or decrease, so at the beginning I do not know all gas substances which might occur or not.

I have a picture how I want the data to be structured/stored in my TDMS file (and hopefully also displayed in the excel TDMS importer) and how it is structured according to excel at the moment.

TDMS example.PNG

I want the cells empty where gas 3 was not present, however, TDMS stores the gas 3 values as depicted. Since I usually also have a column with a timestamp where the data was acquired stored together with the gas concentrations the concentration of the gases kicking in at some time are not in the same row as their corresponding timestamp.

 

Any idea how I can achieve this?

 

0 Kudos
Message 1 of 5
(2,180 Views)

I would recommend either writing 0's or NaN for the measurements where gas 3 is not present, otherwise there's no way that I am aware of to make the data appear as shown on the left. Another option would be to write to a CSV rather than TDMS file in which case the data would appear as you want it to.

0 Kudos
Message 2 of 5
(2,143 Views)
Solution
Accepted by topic author Slev1n

Hey thank you for your answer,

I'd go with your first idea, however, since I dont know how many and which gases will be present I cannot create the channels in advance. So I was thinking, if gas 3 appears to be in the measurement matrix, than I would check how many rows the other channels already contain, add that much zeroes and then continue writing the new data of gas 1, 2 and 3 into its corresponding channel.

So in my example, when the 4th sample is acquired and I notice that a new gas has appeared, than I check how many columns have already been written into the file, so in this example 3. Then I create a new channel called "gas 3" add 3 zeroes and after that, I write the new data array containing the concentration of gas 1, 2 and 3. If later on gas 3 disappears out of my measurement matrix I can easily continue writing zeroes or NaN. And if I notice that another gas (e.g. gas 4) appears I can proceed as before.

 

Would you think this is an elegant solution?

 

kind regards

Slev1n

0 Kudos
Message 3 of 5
(2,115 Views)
I think the approach you are describing makes sense. Another option would be to create a temporary TDMS file where you write each channel to its own group with the corresponding timestamp or sample count. Then once your data collection is complete you could programmatically combine all of the channels into one group in a new TDMS file, adding in the NaN or 0s then. In my mind that's a little more straightforward but either way should work.
0 Kudos
Message 4 of 5
(2,108 Views)

Update:

I sticked to my approach and it works.

 

However, I think your approach is possible but rather complicated since organizing them afterwards means you need a timestamp in each group and then you need to organize your NaN or 0s using these timestamps which I think could be a pain in the a** if many gases have entered/left the matrix several times 🙂

0 Kudos
Message 5 of 5
(2,073 Views)