LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How make for loop with min max value ina Array

I have 1d array with values (for example 1,2,3,4,5) and i need max and min value in array but i cant use Max & Min function. How do this in for loop?

Message 1 of 55
(6,617 Views)

This sounds suspiciously like a homework assignment and as a general rule we try not to do people's homework for them.

 

That said, look up what "shift registers" and "case statements" are and go from there.

 

If you need any more help, please post the code you've written so far so that we can see that your're at least trying.

0 Kudos
Message 2 of 55
(6,602 Views)

This is my first program in LabView and i have no idea how do this.  I try do something but nothing work.

 

 

 

0 Kudos
Message 3 of 55
(6,594 Views)

Have no idea what logic you are trying to implement there.

 

A shift register would be a useful tool, but you don't have any in there.  (I'd use two, one to store the maximum found so far, the other to store the minimum.)

 

Another idea is to Sort 1D Array, then grab the first and last element.

0 Kudos
Message 4 of 55
(6,587 Views)

in C i easy

 

int array[4]={100,200,3003,4444};
for(int i=0; i<3; i++){
if(array[i]>=array[i+1])
array[i+1]=array[i];
}

 

i cant use sort and Min & Max function 😕

 

You are Knight of NI so is simply for you. So i should use 2 shift register?

0 Kudos
Message 5 of 55
(6,579 Views)

That doesn't sound like the problem you described in the opening post.

 

What you described at first sounds like you want to do this:

 

Initialize array, min, max variables

For each element in array

If element > max then ( max = element )

If element < min then ( min = element )

End for

Return max, min

 

But that's not what the C code you posted would do...

0 Kudos
Message 6 of 55
(6,563 Views)

Yes, and only update/overwrite (use a case structure or the "Select" function) the stored min/max values (stored in the shift registers), if the actual value is smaller than the min, or larger than the max...

Just as the C code works... try it, and post what you have as a VI...

0 Kudos
Message 7 of 55
(6,560 Views)

Regardless of the other valid options brought up, the easiest solution is the built in Array Max and Min function. It always helps to look at which functions are actually available.

 

I'm not sure why you say you can't do certain things. My guess is that you're trying to translate your experience in C into this and failing to understand the data flow aspect of LV, which will make you hate LV and write bad code. If you don't see why you can sort the array and take the first and last values of the result, you have to play around with this.

 

Also, I haven't watched these, but they might help you - https://www.youtube.com/channel/UCc6iX8UYixXSQ__oB9NdGjA/videos


___________________
Try to take over the world!
0 Kudos
Message 8 of 55
(6,536 Views)

@tst wrote:

Regardless of the other valid options brought up, the easiest solution is the built in Array Max and Min function. It always helps to look at which functions are actually available.

 

I'm not sure why you say you can't do certain things.


I'm pretty certain this is a homework assignment and the teacher is trying to force the students to learn LabVIEW by starting off making them rewrite a simple function by hand.  It probably says that it has to be done with a FOR loop and not with the built-in function.

0 Kudos
Message 9 of 55
(6,516 Views)

I dont know how start 😕 i am trying to understand how shift register work but i cant. I need array[0] and array[1] how?? help me 😕

0 Kudos
Message 10 of 55
(6,509 Views)