From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format for writing arrays to binary files

Solved!
Go to solution

I'm trying to write to a binary file as a first step in understanding how the saved formats work.

 

Right now, I have two vi's, one writes a single double to a file, and the other writes a 1d array of doubles to a file.

When I read these files into MATLAB, observing the correct format, I successfully get my single double scalar back, but not the array of doubles.  The array comes from 10000 samples of a sin waveform.  I can observe that the output of the sine wave is correct via a waveform graph, and a waveform chart plugged into the Y values of the sine waveform.

I use the same commands in MATLAB for both:

 

fd = fopen('output.bin', 'r', 'b');

input = fread(fd, inf, 'double=>double');

fclose(fd);

Attached are the two variations of the vi.

Download All
0 Kudos
Message 1 of 3
(3,961 Views)
Solution
Accepted by topic author justynnuff

By default LabVIEW writes the size of the array to the first few bytes of the file. I am not sure whether MATLAB interprets that size information. The Write to Binary File has an input to control the saving of the size information.  Try a boolean False wired to "prepend array or string size?"

 

Lynn

Message 2 of 3
(3,954 Views)

Like a charm.  I must have misread that as it defaults to false, thank you.

0 Kudos
Message 3 of 3
(3,949 Views)