LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create a 2-dim array dynamically

Hello!

I have had this problem here before but try one moore time 🙂

This is the thing: We have a text-file from which we read. This textfile can be different from time to time. From this textfile we can catch numbers of columns and numbers of rows that a 2-dim array should have. The problem is how one can create this 2-dim array dynamically? We have a while-loop that the program runs inside already. Must one use the while-loop to solve this problem? Or can one solve this with only a for-loop? Hope you understand how I mean 🙂 Best regards
0 Kudos
Message 1 of 5
(2,848 Views)
If your text file is nicely structured (with well defined seprators for elements and lines) you can use "spreadsheet string to array" to dynamically create a 2D array of the same size. No loops necessary.

If this is not what you mean, please provide an example. How does the file look like? What 2D array should result from it?
0 Kudos
Message 2 of 5
(2,846 Views)
Hello!

I can explain it in this way maybe: One time I want the array to be 4 columns and 10 rows. Another time when the program runs I want the array to be 3 columns and 50 rows. There is a calculation before the array... hmm... the part of the program is in a very huge program and I do not have all the VI-s on this computer...

but the problem is that I want the array to be different sizes from time to time when I run the program... is this more clear? Of course one can initiate an array that have for example 10 columns and then fill the columns that is needed but I wonder if there is a way to create the size from time to time depending on a calculation that is in a sequence before the one where the array is created... I do not know how to explain it... 🙂 Thank you for your answer! Best regards
0 Kudos
Message 3 of 5
(2,837 Views)
OK, I thought you want to read an array of the same size as the actual data in the file. You cannot read a 4x10 array if the file only contains data for a 3x5 array ;).

Is the array size determined by the data in the file or by some other calculation?

I would still read the entire file, then you can cut out a 2D subset using "array subset". This should not be a problem unless you have millions of array elements.
0 Kudos
Message 4 of 5
(2,835 Views)
Hello!

Yes I thought that might be the only way too... that one read the entire file and from that initiate the array...

and then use only the necessary columns and rows...

You asked if the array size is determined by the data in the file or by some other calculation?

The answer is that we have a file and then depending of which elements we are choosing from that file we get the actual size... but the choice one wants to do during the time we build the array :P.

But maybe it is the best way to do that one initialize the array as the greatest number of columns we can have and then "fill it out"...

Thank you for your help 🙂

Best regards.
0 Kudos
Message 5 of 5
(2,822 Views)