LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search 1D array problem

Hey guys,
 
I'm trying to write (what I imagine) is a simple program to progressively step through a text file in array format, honing in on the maximum value, while comparing values along the way (the attached code will do a better job of explaining).  I am aware that I could simply use a maximum value find to obtain what I am looking for, but this is just a simple exercise to simulate something a bit more difficult I'll be doing down the road, thus I have real reasons for doing this all backwards.
 
The problem I run across is when using the "search 1D array" command, it only works on certain elements.  For instance, if you load the code I have attached along with the input file, and input a crystal angle of "40" and a an angle offset of "0.01", then run in highlight mode, you'd see that as soon as it got to search for element 40.02, inside the for loop, it wouldn't find element 40.02 in the file and jump the result to "-1" and keep running, but yielding bogus results.  The problem is that 40.02 DOES exist in the array (search for element 198 in the output array to find it).  In addition, if you input 40.02 as the initial starting angle, with the same 0.01 offset, the first run works just fine (finding element 40.02 this time, when not executing in the loop) but bombing out on the search for 40.06, again yielding a value of -1 when the 40.06 actually exists. 
 
This same type of behavior occurs throughout the array, with certain elements being "un-reachable" via the "Search 1D Array" command when used in the loop, but being reachable when searched for from the initial start, and consistency being shown in the "un-reachable" elements when the code is run over and over.  Again, running the code in highlight mode will clear up any questions about the problem statement, I believe. 
 
Does anyone have an explanation as to why this is occurring and how to fix it?  I thought maybe it was in the string to number conversion, but that doesn't make sense since it can find the numbers outside the loop, but not in it. 
 
I am running Labview version 7.0 for the record. 
 
Thanks!
 
~Jack
Download All
0 Kudos
Message 1 of 7
(2,763 Views)
You get problems because in binary (that's what you use) you get little rounding errors.  Their should be plenty of examples of code failing because of this.
If you expand your display to 12-16 digits you'd see the difference.
Your data is just counting up, you can use 'Threshold 1D array' for this data-type



Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 7
(2,747 Views)

Hello Ton,

i was just looking at his diagram. i think that he doesnt want to use the treshold function, because (from what i understand in his vi), the values might not always go up.

also , he doesnt separate the angle value and its occurence nb. that might be a better solution to have a 2D array in this case, one for the angle, one for the occurence.

but the problem stays: i have looked at the initial txt file, it has just 2 digits of precision. if i take care to use 2 digits of precision for my double comparison value, i should end up being able to do a search the 1D array! otherwise, one should just point out : on Dbl and Ext nbs, the search wont work.

Am i wrong?

 

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Message 3 of 7
(2,738 Views)
I think Gabi may have hit on my problem, and helped me quite a bit.  First I tried the threshold recommendation, but quickly gave that up as I smear my 2d array into a 1d array with values that aren't monotonically increasing, therefore threshold caused some problems. 
 
After reading Gabi's post, I made sure I added a "convert to single precision" statement coming out of the array, and coming out of one of the addition steps, to ensure the data being searched for is all single precision, which allowed the program to run correctly.  So if I understand the single precision thing right, this is an acceptable way to do things, so long as I don't require more decimal places (or precision) than single precision can allow.  Otherwise I'll have to come up with some, more fancy, scheme of processing the data. 
 
Honestly, I wasn't terribly confident (or familiar) with array indexing and accessing in Labview, which is why I converted my 2d array to a 1d in the first place, since there are built in functions for 1d arrays.  If what I am doing can be done more easily in a 2d array, I'd be glad to take the suggestion. 
0 Kudos
Message 4 of 7
(2,732 Views)

Glad i could help, and sorry for stealing the thread Ton.

dont forget to rate!

a very fast improvement you could do on your vi, but that clearly depend on how the data looks:

use the first row of the txt file as the index for the second row. in your case multiply the first row by 100, to get integer values. then you have defined the indexes. the second row you fill following these indexes.

also: try to use shift registers instead of local variables. it is more elegant and less troubles.

good luck.

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Message 5 of 7
(2,727 Views)
I put my and gabi's advice together:



I first had issues in finding any value because my computer takes ',' as the decimal sign instead of '.'

Ton

Message Edited by TonP on 05-29-2007 10:51 PM

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Download All
Message 6 of 7
(2,725 Views)
Thanks to you both for your help!  I will gladly learn good tactics from more experienced programmers than me, and thanks for helping me determine where I was going wrong. 
0 Kudos
Message 7 of 7
(2,694 Views)