12-09-2015 10:23 AM - edited 12-09-2015 10:27 AM
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?
12-09-2015 10:27 AM
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.
12-09-2015 10:37 AM
This is my first program in LabView and i have no idea how do this. I try do something but nothing work.
12-09-2015 10:42 AM
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.
12-09-2015 10:44 AM
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?
12-09-2015 10:53 AM
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...
12-09-2015 10:55 AM - edited 12-09-2015 10:55 AM
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...
12-09-2015 11:11 AM - edited 12-09-2015 11:12 AM
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
12-09-2015 11:24 AM
@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.
12-09-2015 11:39 AM - edited 12-09-2015 11:43 AM
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 😕