LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to append 1D to 2D binary file ?

 

Hello

I stuck on saving binary file.

 

I want to 1D array nesting to 2D array and saving binary file.

After, I would read binary file to matlab.

 

But there have not options to 'append = true' 

 

How can I make 2D binary file ?

 

specially, there are condition. No use build array with shift resistor.

Because, While loop repetition speed would lower gradually.

 

file open - WHILE [ file write(data 1D) ] - file close 

this is basic structure that I only know.

 

 

0 Kudos
Message 1 of 6
(267 Views)

Hi yeers,

 


@yeers wrote:

I want to 1D array nesting to 2D array and saving binary file.

 

But there have not options to 'append = true' 


  • You don't "nest" 1D arrays into a 2D array, you use either 1D or 2D arrays…
  • You already write at the end of the file, so you will append new data to the file.

@yeers wrote:

How can I make 2D binary file ?


A file is a flat stream of bytes, there is no "dimension" (apart from file length) associated with a file!

You just need to parse the file content as needed (and hopefully write the file content in the correct order)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(247 Views)

Since the 2D array will grow, you should not prepend size information, just store it as flat binary, since the column size will grow. Assuming the row size is fixed and known out of band, the column size can be determined from the file size after reading and reshaped into 2D accordingly. as has been mentioned, the concept of a 2D binary file only exists if you chose to prepend 2D size information, which you probably should not do. (Of course you could and then overwrite the column size (bytes 5-8) after each appending operation, but that seems convoluted).

 

As long as you keep the file open, the pointer is after the last write and new data will append No need to set the file position, unless you will append again in a new session later.

 

Can you give a more detailed example of what you are trying to do? What is a shift resistor?

(It is hard to look at a code picture with way too many wire bends and overlapping wires).

0 Kudos
Message 3 of 6
(208 Views)

I have attach simple Vi file 

I hope to explain that What I want.

 

importantly. what I want is speed keep as very high and save 2D array

0 Kudos
Message 4 of 6
(181 Views)

Hi yeers,

 


@yeers wrote:

importantly. what I want is … save 2D array


Then you need to prepare your data as 2D array. Right now you just create a 1D array…

 


@yeers wrote:

importantly. what I want is speed keep as very high


Then you need to create your program with "speed" in mind…

This rules out any kind of ever growing arrays, like you did in that 2nd loop!

 


@yeers wrote:

I hope to explain that What I want.


No, you did not explain very well…

 

Please ask your question with explaining "what" you want to achieve. Right now you focus on "how" you want to achieve your goal (by using some arrays and files)…

 

  • What is your goal?
  • What is the requirement?
  • Where does the data come from?
  • Why did you choose "plain binary" files to save some 1D/2D array data?
  • What is the overall picture? (Don't focus on small subsets of your problem!)
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 6
(172 Views)

As I already said, you should not prepend size information and just write the data. Since you know the row size, you can read it later at once and reshape based on the number of values. Here's a very simple example:

 

altenbach_0-1745589496855.png

(Note that you only need to set the file position before reading if you keep the file open.)

0 Kudos
Message 6 of 6
(147 Views)