Finding maximum value in a sequence
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Andrei Bobrov
2019 年 8 月 8 日
A = randi(1000,1,8);
k = A(1);
for ii = 2:numel(A)
if k < A(ii)
k = A(ii);
end
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!