Finding maximum value in a sequence

11 Ansichten (letzte 30 Tage)
Vahagn Davtyan
Vahagn Davtyan am 8 Aug. 2019
Beantwortet: Andrei Bobrov am 8 Aug. 2019
I want to build a loop, that will compare two values every time and return the bigger one. For example, if say k=5 and b=6 then k>b is false and it should set k equal to 6, and then if my next number is for example, smaller than 6 then it should not change the value of k and should continue comparing k with other values

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 8 Aug. 2019
A = randi(1000,1,8);
k = A(1);
for ii = 2:numel(A)
if k < A(ii)
k = A(ii);
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by