Am trying to reduce a vector by summing some elements in the vector to form another vecter
Ältere Kommentare anzeigen
example if v=[40,34,10,8,6,2] then the new vector will make 40 to be the reference point. after comparing each element the new vector will be N=[40,34,26]
6 Kommentare
Walter Roberson
am 15 Nov. 2017
What are the rules about which elements are to be retained and which are to be summed?
Is the rule that you are to stop summing if the sum would exceed the reference value?
Geoff Hayes
am 15 Nov. 2017
Bashir - why have you decided to sum the elements 10, 8, 6, and 2? Why not include 34 and reduce your v to just
N = [40 50];
Do you just continue adding the elements until their sum is less than 40 (the reference number)? Do you always assume that your array is already sorted in decreasing order?
Rik
am 15 Nov. 2017
Whatever the rules are, a non-loop solution will very likely involve a call to cumsum.
Bashir Yusuf Bichi
am 15 Nov. 2017
Walter Roberson
am 15 Nov. 2017
I suspect this is a case where a loop would be the easiest.
Bashir Yusuf Bichi
am 15 Nov. 2017
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu NaNs finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!