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!