07-17-2016 09:40 AM
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
07-17-2016 12:40 PM - edited 07-17-2016 01:04 PM
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).
07-17-2016 01:00 PM - edited 07-17-2016 01:06 PM
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.)
07-18-2016 06:58 AM
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
07-18-2016 07:29 AM - edited 07-18-2016 07:30 AM
I think you should try it on yourself first..!!
Let me give you a hint:
You can use Build Array function..try it...!
07-18-2016 09:00 AM
@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).
07-19-2016 01:57 AM
07-19-2016 02:41 AM - edited 07-19-2016 03:14 AM
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 ;))
07-19-2016 03:07 AM - edited 07-19-2016 03:08 AM
@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.
07-21-2016 12:14 AM
OK, great,
thanks a lot for your time!!