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!