cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with double for loop... help!

Fonsi
Active Participant

Problem with double for loop... help!

Message contains an attachment
Hi,
 
I am very stuck, with this problem, i suppose is stupid problem, but i cant see it..
 
I attached the vi. My problem is when I use the double for loop to looking for the values of source array between 2 elements from another array, when the vi 'search 1d array', when the values is out of range, put 0 on the rest of array elements, and i would like remove all the 0, i want the double for loop, show only the index from the values between these elements. I know each time the for loop search the range, and when it doesn't find any value put 0, but i dont know do thats!!
Any help?
 
Regards Fonsi.
 
 

Mensaje editado por Fonsi

5 REPLIES 5
Chaos
Active Participant

Re: Problem with double for loop... help!

Message contains an attachment
Sorry if I mis-interpreted your request.  I cleaned up the front part some by replacing the two unneeded formula nodes with plain old arithmetic functions and also, if I understood you right, fixed the back end.  All I really did was change the build array to remove the zeros and bundle them into a cluster so each can have variable lengths.
 
If this is not what you wanted please let us know so we can make further modifications...
 
Fonsi
Active Participant

Re: Problem with double for loop... help!

Message contains an attachment

Hi Chaos,

Thanks for the fast reply....

Well, it solves it, but i need 2D array of index of elements, and putting the bundle, i got 1d array of cluster, any way to maintain 2d array with the elements wihtout 0 values??.

I need the output for another calculates...

Regards, Jose.

Chaos
Active Participant

Re: Problem with double for loop... help!

Message contains an attachment
Hrph... lemme think.  Well the only thing I can think of offhand would be to change the representation to double and replacing the unneeded zeros with NaNs (not a number).  See example of one possible implementation.  Otherwise I cant think of anything else...
altenbach
Knight of NI

Re: Problem with double for loop... help!

Message contains an attachment

As Chaos said, A 2D array must have the same lenght for all rows. NaN is a good idea and you can just check for its presence in the later code to determine the end of the current trace.

However, you should generate the NaNs at the beginning. Replacing zeroes with NaNs after the calculation can accidentally wipe legitimate zeroes. Smiley Wink

I have made a quick modification that also shows some simplifications to your code.

  • Don't use formula nodes for simple add or multiply. LabVIEW is graphical!
  • Same for the big formula. Use wires, no FOR loop needed here! Smiley Very Happy
  • If you want to index element i and element i+1, grow the node and wire i to the first terminal. The second output will be i+1. Isn't that nice? Smiley Very Happy
  • Don't use local variables in a case like this. They break dataflow.
  • Use  In "Range and Coerce" instead of multiple comparisons.

See attached example (LAbVIEW 7.1). Let me know if you have questions. Smiley Happy

Message Edited by altenbach on 09-29-2005 05:24 PM

Highlighted
Fonsi
Active Participant

Re: Problem with double for loop... help!

Hi Chaos,
 
Thanks for the help, it works!. On the next calculates i put if estructure, putting if value is = 0, dont operate.. so maintain the size of array and later when i join all, i can get only the ok values...
 
@Altenbach
 
Thanks for the free lessons Smiley Wink, you always showing new things to program... thanks a lot, i think i improved a lot from the last 2 year in labview, is true I use easy programation, and i use a lot of for loop and local variable, since i must confirm all the data before, but honestly I do all the program so + or - Smiley Happy.
 
The trick use +1 from the index array is true, never think that !! sad Smiley Happy. I never used 'Range and Coerce', and it is great!. Thanks.
 
I I learn a lot with you, very kind.