- What do you want to do if the minimum is not unique?
- What do you want to do if the minimum is at the right end of the vector?
Array selection
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I have one array, for example: A=[10 6 8 9 11] and I take the min of it which is number 6. How can I select only the three numbers which is on the right of number 6? I mean I want a function to select numbers 8, 9, 11 (only them and not 10) and sum them all (8+9+11). However, I want this function to work for random arrays and not only for array A. I mean this function will always select the numbers that are on the right of the minimum number of an array and will sum them all.
If anyone knows, I will be grateful!
Thank you..
0 件のコメント
採用された回答
the cyclist
2011 年 2 月 26 日
Is this homework?
Here is some code that will do what you want:
[MinA indexToMinA] = min(A);
rightOfMinA = A(indexToMinA+1:end);
sumRightOfMinA = sum(rightOfMinA);
There are at least two things you need to be careful of with this simple solution:
These can be handled easily, once you know what you want to do. Maybe you can work that out for yourself. (I suggest a careful read of "doc min", too.)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!