Count Each Maximum Number in an Array That's Larger Than Previous Max Number
조회 수: 3 (최근 30일)
이전 댓글 표시
For example if I have
a=[1,2,4,3,4,7,4,9,3,4,10,4] then the numbers I would need to count are 1,2,4,7,9,10
So this isn't necessarily looking at if the number is larger than the number before it, but if it's larger than the previous maximum number.
This is not my actual homework, I'm just using this as an example so I can apply it my homework.
댓글 수: 0
답변 (3개)
Star Strider
2017년 6월 7일
There are probably a number of different ways to do this.
One approach:
a=[1,2,4,3,4,7,4,9,3,4,10,4];
q = [];
for k1 = 1:length(a)
q(k1) = max(a(1:k1));
end
Out = unique(q)
Out =
1 2 4 7 9 10
댓글 수: 0
Image Analyst
2017년 6월 7일
A simple for loop should do it:
newMax = [];
for k = 1 : length(a)
if ......
newMax = [.....
end
end
March along the vector, building up the list of values "newMax" everytime you encounter a value more than newMax(end).
There are other ways but this might be the simplest.
댓글 수: 0
Steven Lord
2017년 6월 7일
Since this is related to a homework question I'm only going to give a hint: you may find the cumulative maximum function useful.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!