- 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!