LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert a 2D array into the end of X axis of the initial array?

Hi, friends, I have a question and look for an advice. I have several input data, each of which has 4 rows and unknow columns. Each time I receive the input, I need to combine it to all of the previous ones by adding it to the end of X axis of the previous combined data. I must do it because, later, I need to run my model and my model read input for each column of 4 rows. How should I do it? Also, should I initiate an array before reading all of the inputs? The inputs are F32 format. Thank you very much for any of your advice.
0 Kudos
Message 1 of 6
(3,161 Views)
Ccyang,

there are more than one solution. Choosing the best one depends on what you want to do and how.
Assuming that speed is not the most important aspect, I'd suggest simply to append the data in all of the channels. So in pseudocode:
* index all four rows from both the combined data and the arrived ones
* append the respective rows from both the combined and the arrived data; choose 'concatenate' with the build_array node
* build the newly combined data rows together into a 2D-array.

For speeding things up, use a while loop with some shift registers. keep the indexed rows from the combined data separate, so you can omit the indexing and array_building with each iteration.
If you know the desired overall size of your data, you can as well initialize those rows and replace the data. But this helps just if you literally get thousands of small chunks of data to append AND if your PC is low with RAM.

Greetings from Germany!
--
Uwe

Message 2 of 6
(3,143 Views)
Building a 2D array row-by-row is easy. You either use "build array" if you need to update the indicator during the run, or you simply autoindex at the loop  boundary (FOR or WHILE).
 
Two possibilities are shown in the attached image. If your arrays are getting large and you use a while loop, there are possibilities that are more memory efficient. You would initialize a 2D array (e.g. filled with NaNs) of an upper boundary of the final expected size, then replace rows as you go.
 
(Notice that if you use autoindexing on a FOR loop, the final size is known from the beginning so memory can be allocated efficiently)
 

Message Edited by altenbach on 11-01-2006 09:19 AM

Message 3 of 6
(3,135 Views)

Dear friends: Thanks a lot fo your suggestion. However, I think I did not state my problem correctly. I am sorry for this. I need to read input data, each time the data has 4 rows and n columns. N varies from data to data. I need to put the data all together until the signal comes and all of the data go to the model. When m of the data goes to the model, it has 4 rows and n1 + n2 + n3 + n4 + ... + nm columns. And the timing is very essential since the next group of data comes in lss than 0.4 second.

You see, I don't have time to transpose each data and combine them row by row, but Insert Array and Replace Array all assume that I will put the new data after the end of row of the previous combined data. Instead, I need to pu the new data after the end of column of the previous combined data. Do you have a good idea how to do it?

By the way, when I start to accumulate data, do I need to initiate an array before reading the first input?

Thanks again for all your help. A big thank from Taiwan/Canada.

0 Kudos
Message 4 of 6
(3,118 Views)
Ccyang, I think my explanation was not clear enough. See the attached BD. This little code simulates your data as a block of 4 rows with 99 elements each. AND, on my machine, this takes about 0.85 ms per iteration. Even with slower CPUs, there should be enough room to mmet your timing restrictions of 0.4 s ;-)) My expectations may not be correct to the last digit, but for my example code, the simulation probably takes >90% of the CPU usage of that code. HTH and
Greetings from Germany!
--
Uwe

Message Edited by LuI on 11-02-2006 09:22 AM

Download All
Message 5 of 6
(3,108 Views)
Thanks a lot, lul. I think your code is exactly what I need. And thank you too all of you who sent me different suggestions. They all help a lot.
0 Kudos
Message 6 of 6
(3,086 Views)