LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a dynamic 2xN array?

Hey All,

I've got a question that seems pretty easy in concept but for some reason I just can't quite figure it out. All I want to do is run through a matrix using for loops and if a value in that matrix is equal to the value I set (my cutoff value), I take the coordinates (the iterations of the loops) and pop them into an array, which I hope to use as a set of graphable points. So I start out by building a 2x1 1D array from the two points I get (my loop iterations again, which would represent my X and Y values), by using the Build Array VI. Now I try feeding that into another Build Array VI that has a feedback loop on it which feeds back into itself. The output from this is then sent to an Array Size VI (which is outside the loops) so that I can see just how big my 2xN array got.

Now the good news is that I do get a 2D array as an output. The bad news is that try to get the data exactly when my cut off point occurs (ie. if(data == cutoff) ) I get no size, but if I created a range of even one lower (ie. if( (data <= cutoff) || (data >= (cutoff-1))) ) then the size of my array turn out to be 2x49152, which is the total range of my data (192*256). Now I know for a fact that not every point in my data is one less than my cutoff point (which is the maximum value in this case) as I have a meshing that shows me the values. I also thought that maybe conflicting data types might be a problem, so I converted my cutoff value from a int to a float type. No dice there either. Soooo, I figure it must be some underlying logic that I'm missing or something that LabView does differently than I expect.

I guess my actual question is this then: Why does LabView gives me either a 0 element array or a complete array (as in ALL the data points not just the ones at the cutoff value)? Also if there is a better way to build the array than this. I have attached a picture of my current set up that retrieves the data points, builds the 2xN array and gets the size. If there's any other part that you may need to see, just let me know.

Thanks,
Phil

[url=http://img114.imageshack.us/my.php?image=buildinganarrayjl7.jpg][img=http://img114.imageshack.us/img114/3226/buildinganarrayjl7.th.jpg][/url]

P.S. Here's an direct link to the image if the above doesn't work: http://img114.imageshack.us/img114/3226/buildinganarrayjl7.jpg
0 Kudos
Message 1 of 4
(2,695 Views)

I decided to post your picture to make things easier for othersSmiley Wink -SS



Message Edited by ShotSimon on 08-12-2008 04:57 PM


Message 2 of 4
(2,680 Views)
If I understood you correctly, you want to find the indices where the array element value matches a certain fixed value. One thing you must understand is that you must never perform equality operations on floating point values with computers. Computers operate in base 2, while you operate in base 10. It is not possible to precisely represent a floating point number using computers. This issue comes up a lot. How you choose to do the comparison depends on your numbers and what level of precision you want.

That said there is no need to use a formula node for simple arithmetic. LabVIEW has functions to do that, and they're much faster than using a formula node. Don't try to write LabVIEW code using text-programming techniques. It won't work. I don't use Feedback Nodes because I hate them. I prefer shift registers since they're much easier to understand, and you can't accidentally flip their direction. Here's a simple implementation using shift registers. That little white plus function is a custom function to check if a floating point value is approximately equal to some value, within a specifed number of decimal places.



Message Edited by smercurio_fc on 08-12-2008 04:59 PM
Message 3 of 4
(2,678 Views)
Wow that was quick.

Thanks a lot guys, I'll try that stuff out tomorrow, and I'll get rid of that floating point comparison and formula nodes for more efficiency.

-Phil
0 Kudos
Message 4 of 4
(2,666 Views)