04-23-2025 11:32 PM
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.
04-24-2025 12:29 AM
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'
@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)…
04-24-2025 09:59 AM - edited 04-24-2025 10:01 AM
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).
04-24-2025 07:56 PM
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
04-25-2025 12:49 AM
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)…
04-25-2025 08:59 AM - edited 04-25-2025 09:00 AM
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:
(Note that you only need to set the file position before reading if you keep the file open.)