LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested for loop

I have two array, one is 1d array named a[SIZE ],another is 2d array named b[ ][ ]. I want to find out the minimum difference in array a and store the value to array b. here is the c code:
 
for (i=0;i++;i<SIZE)
     for (j=0;j++;j<SIZE)
   b[ i ][ j ]= a[ i ] - a[ j ];
 
Could anybody tell me how to program this in LabView?
Thanks ~_~
0 Kudos
Message 1 of 5
(2,916 Views)

Hi Chen,

      Attached are two VIs, "Diff.vi" implements your example exactly, it outputs the minimum value of the subtraction and the corresponding indexes.   

If you want to locate two values from A with the least difference between them, Diff_abs.VI is a little more efficient.

Cheers! 

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Download All
Message 2 of 5
(2,907 Views)
It is very useful. Thank you so much ^_^
0 Kudos
Message 3 of 5
(2,901 Views)


@chenli868 wrote:
for (i=0;i++;i<SIZE)
     for (j=0;j++;j<SIZE)
   b[ i ][ j ]= a[ i ] - a[ j ];

A literal translation would be the following:

Message Edited by altenbach on 08-16-2007 09:58 PM

Message 4 of 5
(2,894 Views)

Hi chen,

      Your welcome! - but be warned: Diff.vi has a bug! Smiley Surprised

Diff_abs.vi is OK, but go with Altenbach's code if you really want the N by N array.

(I tested Diff_abs.vi then partially gutted-it to make Diff.vi which wasn't tested Smiley Tongue -)

Cheers!

Message Edited by tbd on 08-17-2007 12:29 AM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 5 of 5
(2,890 Views)