LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

get a portion of a row from a 2D array in one step

Solved!
Go to solution

Is there a function in LV that will return a *portion* of a row from a 2D array in one step?

 

I know I can cascade two Index Array functions, first to pull out the row, and second to grab a section of it.

 

I think there is no way to do this with a single function like Index Array or Array Subset. It looks like Labview will only return single data points at a given row, column index, or entire rows or columns.

 

It's true that I'm stuck in LV 2014 at the moment. Maybe the feature has been added in later releases?

 

I can write my own silly little sub VI to do it but it feels like it should be built in. I'm just obsessing and need someone to tell me to fuggedabowdit.

 

Thanks!

0 Kudos
Message 1 of 9
(591 Views)

aputman_0-1703111505128.png

 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 9
(582 Views)

I've tried this repeatedly and it always returns a 2D array no matter how I wire it.

 

Can you show an example of a 2D array input returning a 1D array?

 

I expected that I'd wire a row index and a column index and get the remainder of that row beginning with the column indexed

 

I'm sorry if I'm being dumb.

0 Kudos
Message 3 of 9
(564 Views)

I was being dumb. I needed to wire the row input length as 1.

 

Sorry. Can we delete this thread?

0 Kudos
Message 4 of 9
(558 Views)

I wish I could edit my replies.

 

The function IS returning a portion of a row, but it's returning it as a 2D array. That's what's been confusing me. It's really only a 1D array of data, and I expected a 1D array out, but it's being treated as a 2D array with a single entry in the row dimension.

 

I suppose it makes sense not to change the dimensions of the subset returned. Or maybe it makes better sense to do that? I don't know.

 

I have to use Reshape Array, so it's still a two stage process.

0 Kudos
Message 5 of 9
(547 Views)
Solution
Accepted by topic author techgineer

I don't believe there is. Your issue relates to typing. A node must be able to tell, at edit time, exactly what type you're looking to return.

 

All of the Array VI's can take any dimension arrays as inputs. The algorithms therein decide, again at edit time, what size the return should be. If you provide Index Array with an n-dimensional array and m inputs, it will return an (n-m) dimensional array as its return. For example: a 3-dimensional array with 1 "Index" input will return a 2-dimensional array.

 

Array Subset is similar. It accepts an n-dimensional array, and splits each of those dimensions, returning a smaller but still n-dimensional array. There are a couple reasons for this, but generally speaking any subset of an n-dimensional array is still an n-dimensional array- even if the length of some of those dimensions is 1. A 2D array of length [5, 1] is still a 2D array.

 

Now, the compiler CAN make exceptions here, and you could say "OK, if one dimension is 1, just knock off one dimension from the result." This works if you have a constant on the block diagram, but what if that input is a variable on the front panel? The typing is done at edit time, but that value would only be known at run time. So in that case, you'd need to always be checking constants and interpreting the output, formatting things differently if it's a 1 vs. anything else, etc. This CAN be done- but it's not a very common occurrence. In your case, you just need a pair of nodes instead of a single node, so it's no huge deal.

 

As a note that there ARE times when nodes change behaviors, but they're for situations with no ambiguity on the output type (for example, Array Size changes output type to Scalar if the input array is 1D). In your case, it would require changing type for the output for only a constant of 1, and it could be ambiguous when you actually want the arrays to stay 2D (even if one dimension is 1).

 

*At this point in my rambling I'd like to note the dual purpose of this post, which is to try to be helpful while at the same time invoking Cunningham's Law 🙂

0 Kudos
Message 6 of 9
(539 Views)

Reshape array is the wrong solution. I have to use Index Array.

 

So for my particular application, two cascaded Index Array is the simplest and cleanest solution. Array Subset adds a lot of complication.

0 Kudos
Message 7 of 9
(532 Views)

Thanks for your reply. I see your point. I was trying to think simple and it's a complicated issue.

 

I'll stick with cascading a a couple of Index Array functions. It's much cleaner.

0 Kudos
Message 8 of 9
(526 Views)

Even if you're just using a couple Index Arrays, it sounds like it'd be a good use of a subVI. It could make your code cleaner and easier to read.

 

(From prior experience, I'd recommend calling it something like "Get pixel intensity values" or "Get list of orders", not "Get 1D array subset from 2D array". The first is somewhat "self documenting". Though the second is more generic and may offer better reuse, you'd want a comment in there describing why you're looking at a certain offset and length. I'd take the tradeoff of needing to reproduce the simple VI if I needed it again rather than trying to make everything super duper reusable, which is certainly a noble cause but isn't the ONLY important thing for code).

0 Kudos
Message 9 of 9
(517 Views)