LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Row operation on array with a For Loop

Solved!
Go to solution

Hi,

 

I'm working with a large one dimensional column array. I'm trying to do the following

 

for i=1:size(A)/2

 

B(i,: ) =A(1+(i-1)*2:i*2)

 

 

So, for example if

A=          

0

1

2
3
4
5
6
7

 

then

B=             

 

0 1

2 3
4 5
6 7

 

My approach was to use an array subset block inside the for loop to select a number of elements but I'm not sure how to transpose the selected elements into a new row to create the new array B. Is there a more straightforward approach?

 

Thanks,

Mike

 

 

0 Kudos
Message 1 of 3
(2,501 Views)
Solution
Accepted by topic author quasarman

try experimenting with the reshape array feeding it your input array and re-sizing it to output a 2d aray. It is much faster than using a For loop becuase the data never gets moved and LV just changes the array dimensions and updates the stride.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 3
(2,495 Views)

Thanks, I tried it with reshape and its much easier.

0 Kudos
Message 3 of 3
(2,471 Views)