06-03-2022 01:42 AM
Hi,
I have a binary file written in LabVIEW 2021. The data format is as in figure below.
I would like to read the data in Matlab 2017. I am reading data as below:
gain=1st 64 bits
offset= next 64 bits.
sampling Rate 1= next 64 bits
Sampling Rate 2 = next 64 bits.
And so on.. Am I reading the data correctly? Is my assumption correct that data is written sequentially without any embedded information about cluster and other controls etc?
06-03-2022
02:21 AM
- last edited on
05-05-2025
04:09 PM
by
Content Cleaner
Have a look at the flattened data documentation: https://www.ni.com/docs/de-DE/bundle/labview/page/flattened-data.html
I am assuming the data was written using Write to Binary File. What you need to know is that arrays and strings are prepended by an int32 indicating the number of array/string entries. Like you said, there is no type information stored in the flattened data and also no padding (leaving out classes for now).
In your example the array length is missing and the data length for Sampling Rate is too big.
The flattened layout for your cluster should be:
int32 scaling coefficient array length
f64 gain[0]
f64 offset[0]
...
f64 gain[n-1]
f64 offset[n-1]
u16 Sampling Rate 1
....
06-03-2022 06:38 AM - edited 06-03-2022 06:40 AM
Hi,
Thank you for prompt response. I am using Write to Binary File. I have follow up questions:
1. Does cluster also prepended with int32 indicating number of elements?
Thanks
06-03-2022 07:04 AM
jayantbala@gmail.com wrote:
1. Does cluster also prepended with int32 indicating number of elements?
No. But your strings and arrays inside of the cluster will regardless of the "Prepend Array/String Size" setting.
Another thing of note is that Matlab defaults to a byte order of Little Endian while LabVIEW defaults to Big Endian. It is a simple input on the LabVIEW side if you want to make it easier for the Matlab side.
06-15-2022 06:31 AM
Hi,
Can you please elaborate your earlier suggestion " In your example the array length is missing and the data length for Sampling Rate is too big".
Also, the the suggested link on flattened data seems broken . Is there any alternate link?
06-15-2022 07:16 AM
jayantbala@gmail.com ha scritto:
Hi,
Can you please elaborate your earlier suggestion " In your example the array length is missing and the data length for Sampling Rate is too big".
Also, the the suggested link on flattened data seems broken . Is there any alternate link?
According to your printout, you are writing 4 sampling rates, each long 16 bits.
Thus, if you declare
sampling Rate 1= next 64 bits
Sampling Rate 2 = next 64 bits
...
you are reading 8 bytes instead of 2 for each sampling rate. Too long.