- 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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
the cyclist
am 26 Feb. 2011
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!