- #1

- 590

- 0

**matlab command "while"**

we recently learned about loops in matlab, more specifically the while command, from what i understand, MATLAB will continue with the set command as long as the condition i chose is true.

as an excercise we had to make a program that will give me the highest value in a given matrix

what i tried doing was:

a=rand(5)

i=1

max=a(n)

while a(n)<max

n=n+1;

max=a(n);

end

what i thought this would do was take a random 5x5 matrix, start from a(1,1) and find the largest value,,, not so,

how can i make such a program using "while", not "if", what i want it to do is take a loop and keep on adding 1 to the previous n, keeping the largest value as max