Sort elements of Array by given condition
Ältere Kommentare anzeigen
Hello,
i have a vector n 480x1 and would like to sort the vector so that the condition
sum(([n ;0]-[0 ;n])>0)==68
is given. How could i do this? my approach was to realize a permutation of the vector until the condition is given. Unfortnely, this takes too much time.
Thanks in advance
5 Kommentare
Dyuman Joshi
am 28 Dez. 2022
Bearbeitet: Dyuman Joshi
am 28 Dez. 2022
That will depend upon the values of the vector.
You might not achieve that condition if all the values are monotonically increasing or decreasing.
Or do you want to change the indices of the values (jumble them up) to get this specific condition?
Daniel
am 28 Dez. 2022
Dyuman Joshi
am 28 Dez. 2022
Please attach your data using the paperclip button.
Although, I must say that it might be a challenging task to do so.
Daniel
am 28 Dez. 2022
Akzeptierte Antwort
Weitere Antworten (1)
load('vector.mat')
XR1 = [xr;0]; XR2 = [0;xr];
IND = (XR1-XR2)>0;
ii = 1;
S = 0;
while S~=68
S(ii+1) = S(ii)+IND(ii);
ii=ii+1;
end
fprintf('Summation is halted at %d step and the sum is %d \n', ii, S(ii))
Kategorien
Mehr zu Shifting and Sorting Matrices 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!