How can I get subscript instead in indices from sort() ??
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
JAI PRAKASH
am 7 Aug. 2018
Kommentiert: Fangjun Jiang
am 7 Aug. 2018
How can I get subscript instead in indices from
sort(mat(:));
Script:
%%Creation of 'mat'
mat = magic(100);
for i=1:100*100
mat(mat>(100*i-100) & mat<=100*i)=i;
end
[~,idx] = sort(mat(:));
%%I dont want to use 'for' loop. I.e.,
for i=1:length(idx) % I want to avoid for loop
[I(i),J(i)] = ind2sub(size(mat),idx(i));
end
I tried 'arrayfun' also but it is taking more time then for loop
[I2,J2] = arrayfun(@(x) ind2sub(size(mat),x),idx);
1 Kommentar
Fangjun Jiang
am 7 Aug. 2018
mat(:) turns mat() into a column vector. No point to get indices anyway.
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!