How to efficiently sort a vector relative to a reference vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
balandong
am 24 Nov. 2017
Kommentiert: balandong
am 24 Nov. 2017
Dear Coder, The objective is to sort a matrix B with respect to the number in a vector A. The following code was implement to achieve the objective. However, I wonder if another more compact (w/o the FOR loop) can also be realize?. I really appreciate for any suggestion.
load('help_sort.mat');
RefMats=RefMat;
ToSorts=ToSort;
c_m=1;
row_locv_CELL=zeros(1,size(RefMats,1));
for f_x=1:size(RefMats,1)
row_locv_CELL(c_m)=find(ToSorts(:,1)==RefMats(f_x));
c_m=c_m+1;
end
relative2REF=ToSorts(((row_locv_CELL))',:);
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 24 Nov. 2017
Bearbeitet: Andrei Bobrov
am 24 Nov. 2017
[~,ii] = ismember(RefMat,ToSort(:,1));
relative2REF = ToSort(ii,:);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices 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!