LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I extract every n-th row from a 2D array?

Hi everyone,

 

I was trying to solve this problem without success,

I need to extract every n-th row from a 2D array.

 

So for example:

I have a 2x2 matrix with 768 rows,

and I want to extract every 9-th row, starting from the first one (which is the first to be extracted).

I chose these numbers as an example to clarify that 768/9 does not has to be an integer.

 

Thanks a lot,

Shai 

 

0 Kudos
Message 1 of 10
(5,214 Views)

This is a trivial problem once you are familiar with array operations. Please show us your failed attempt and we will correct it.

 

A 2x2 matrix does NOT have 768 rows, just two. Do you mean you have a 2-dimensional array?

 

You also don't really say what you mean by "extract". Where should it go and what should happen to it?

 

(In LabVIEW, a "matrix" is a special typedef for a 2D array, useful for linear algebra, so don't use that word unless you mean it).

0 Kudos
Message 2 of 10
(5,202 Views)

Try something like this.... (there are many ways to do it, of course!)

 

(This will create a new 2D array with only the extracted rows retained.)

 

 

 

Download All
0 Kudos
Message 3 of 10
(5,194 Views)

Thanks a lot !!!!!!!

This was extremely helpful !!!!

 

Can I ask you another question, please?

 

All this is inside a while loop, so every loop creates a 2D array (for example 3x4).

I would like to append all the 2D arrays from all the loops to a single 2D array.

For example if the loop runs 5 times, and each run produces 3x4 array,

then at the end I'll have 15x4 array (all of them stacked one below the other).

 

I'm trying to solve this with feedback nodes and shift registers but I cant get it right.

 

Thanks,

Shai

 

0 Kudos
Message 4 of 10
(5,137 Views)

I think you should try it on yourself first..!!

Let me give you a hint:

You can use Build Array function..try it...!

0 Kudos
Message 5 of 10
(5,128 Views)

@shai.yefet wrote:

I'm trying to solve this with feedback nodes and shift registers but I cant get it right.

 


You are not giving us any useful information to narrow down the problem. There a dozens of ways to get it right and millions of ways to get it wrong.

Please show us your code and we tell you what's wrong.

Typically you would use build array to append. If you want to maintain the same domensionality (2D), make sure "built array" is set to append (rght-click).

0 Kudos
Message 6 of 10
(5,107 Views)
Hi,
 
The code is complicated and reads data from a DAQ system, so I've attached a reduced version of it.
The important thing is the 2D array in the right side of the main while loop.
In the full version of the code, each iteration in the while loop performs a lot of calculations, 
but in the end every iteration produces a 2D array, and I want to append them side by side.
 
For example:
the 1-st iteration produces:
a  b  c
d  e  f
and the 2-nd iteration produces:
A  B  C
D  E  F
 
So I want at the exit of the while loop to have:
a  b  c  A  B  C
d  e  f  D  E  F
 
I tried with build array or insert into array but what do I do with the first iteration?
There's nothing to append into..
 
I've also tried tunneling the result out of the while loop with auto-indexing,
but that creates a 3D array (each iteration produces a page in the 3D array)
and I don't know how to stack all the pages side by side.
All this should go into a file, but the write-to-file expressVI receives only 2D array.
 
Thanks for you efforts,
Shai 
0 Kudos
Message 7 of 10
(5,066 Views)

The main problem is poor planning for your data structures. Appending successive 2D arrays with new columns is inefficient because the new data needs to be interlaced in memory. The elements don't remain in memory order so there is a lot of data shuffling behind the scenes. One possibility around that is to append the transposed arrays and transpose for display at the end.

 

The attached show two possible solutions.

 

If you really know the final array size beforehand, it would be much easier and efficient to allocate the entire array with NaNs and use "replace array subset" to replace with real data as itt arrives. (not shown. You'll figure it out ;))

 

 

0 Kudos
Message 8 of 10
(5,060 Views)

@altenbach wrote:

If you really know the final array size beforehand, it would be much easier and efficient to allocate the entire array with NaNs and use "replace array subset" to replace with real data as itt arrives. 


Here's a simple example for that.

0 Kudos
Message 9 of 10
(5,052 Views)

OK, great,

thanks a lot for your time!!

0 Kudos
Message 10 of 10
(5,000 Views)