LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write 1-D numerical array into binary file, and start with a new line or insert a delimiter for each loop writing file

Solved!
Go to solution

Hi: 

  I am struggling with writeing 1-D numerical array into binary file, and start with a new line or insert a delimiter for each loop writing file. So for every loop it runs, the LABVIEW code will collect a 1-D array with 253 elements from a spectrometer. When I write those arrays into binay file, and the next array will just stack after the previous array(I used MATLAB binary file read). However whenever if there is the data point missing, the whole array is shifted. So I would like to save the 1-D array to  N-D array, and the N will be how many times has the loop run. 

 I am not very familiar how does Binary Write from file I/O works? Can anybody help understand that? I tried to use file position, but that function is just for write string to binay. But I really want to write 1D numerical array to N-D array. How can I do that.

Thanks in advance 

Download All
0 Kudos
Message 1 of 4
(3,578 Views)

Look at the help for binary file writes. It looks like you are appending a length at the beginning of each write. That will mess Matlab up if it is not expecting it.

 

Once that problem is solved, you need to realize that a binary write is a flat file structure. Tell Matlab to read N points thaen divide those points into M arrays. (There is no concept of arrays in a flat binary write.)

 

Cheers,

mcduff

0 Kudos
Message 2 of 4
(3,574 Views)

So how can I do not appending a length at the beginning of each write? Is there a way to do that\?


@mcduff wrote:

Look at the help for binary file writes. It looks like you are appending a length at the beginning of each write. That will mess Matlab up if it is not expecting it.

 

Once that problem is solved, you need to realize that a binary write is a flat file structure. Tell Matlab to read N points thaen divide those points into M arrays. (There is no concept of arrays in a flat binary write.)

 

Cheers,

mcduff


 

0 Kudos
Message 3 of 4
(3,556 Views)
Solution
Accepted by topic author lawsberry_pi

@lawsberry_pi wrote:

So how can I do not appending a length at the beginning of each write? Is there a way to do that?


On the top of the Write Binary File is a boolean input called "Prepend Array/String Size (T)".  It defaults to TRUE.  Set it to FALSE.

 

Also be aware that Matlab likes Little Endian while LabVIEW defaults to Big Endian.  So you should probably set your endianness on the Write Binary File as well.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(3,549 Views)