Error using unique command
Ältere Kommentare anzeigen
I have two values
A = [1000 16000 100000 30000 2000]
B = [150 100 4000 5000 2000];
I used code below to get the Sorted value of B according to A:
[ii jj k] = unique(A);
B = unique(B);
P = B(k);
C = [100 4000 2000 5000 150];
If my values of A are from -400 to 400 and and values of B are from -100 to 100 I get the error :
Index exceeds Dimension
Please provide assistance.
Akzeptierte Antwort
Weitere Antworten (2)
Salil Goel
am 24 Nov. 2012
0 Stimmen
Are you making sure that the size of A and B is same when values in A are from -400 to 400 and B from -100 to 100? If not, then obviously you would get this error.
% Sort B the same way A is sorted.
% We only need two calls to SORT.
[~,J] = sort(A);
BSA = sort(B);
J(J) = 1:length(A);
BSA = BSA(J) % This is B, sorted the same way A originally was.
5 Kommentare
Pat
am 29 Nov. 2012
Azzi Abdelmalek
am 29 Nov. 2012
Pat can you post an example
Pat
am 29 Nov. 2012
Azzi Abdelmalek
am 29 Nov. 2012
What is the difference with the previous example?
Pat
am 29 Nov. 2012
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!