
نوشته شده توسط
rahnema1
اصلا فکر کنم sortrows نداره
u=unique([i;j]);
h=hist([i;j],u);
[ss ii]=sort(h);
hh1=u(ii(numel(ii):-1:1));
rng=[];
dex=1;dex1=1;
while( rows(ij)~=0)
[m n]=find(ij==hh1(dex));
ij(m,:)=[] ;
if (numel(m)>0)
rng(dex1)=hh1(dex);
dex1=dex1+1;
end
dex=dex+1;
end
in(:,rng)=[];
out = data(:,end);
sortrows داره مهندس. اینم syntax :
Sort rows in ascending order
syntax
B = sortrows(A)
B = sortrows(A,column)
[B,index] = sortrows(A,...)
Description
B = sortrows(A) sorts therows of A in ascending order. Argument A mustbe either a matrix or a column vector.
For strings, this is the familiar dictionary sort. When A iscomplex, the elements are sorted by magnitude, and, where magnitudesare equal, further sorted by phase angle on the interval
.
B = sortrows(A,column) sortsthe matrix based on the columns specified in the vector column.If an element of column is positive, the MATLAB softwaresorts the corresponding column of matrix A in ascendingorder; if an element of column is negative, MATLAB sortsthe corresponding column in descending order. For example, sortrows(A,[2-3]) sorts the rows of A first in ascendingorder for the second column, and then by descending order for thethird column.
[B,index] = sortrows(A,...) alsoreturns an index vector index.
If A is a column vector, then B= A(index). If A is an m-by-n matrix,then B = A(index,:).
Examples
Start with a mostly random matrix, A:
rand('state',0)
A = floor(rand(6,7) * 100);
A(1:4,1)=95; A(5:6,1)=76; A(2:4,2)=7; A(3,3)=73
A =
95 45 92 41 13 1 84
95 7 73 89 20 74 52
95 7 73 5 19 44 20
95 7 40 35 60 93 67
76 61 93 81 27 46 83
76 79 91 0 19 41 1When called with only a single input argument, sortrows basesthe sort on the first column of the matrix. For any rows that haveequal elements in a particular column, (e.g., A(1:4,1) forthis matrix), sorting is based on the column immediately to the right,(A(1:4,2) in this case):
B = sortrows(A)
B =
76 61 93 81 27 46 83
76 79 91 0 19 41 1
95 7 40 35 60 93 67
95 7 73 5 19 44 20
95 7 73 89 20 74 52
95 45 92 41 13 1 84When called with two input arguments, sortrows basesthe sort entirely on the column specified in the second argument.Rows that have equal elements in the specified column, (e.g., A(2:4,:),if sorting matrix A by column 2) remainin their original order:
C = sortrows(A,2)
C =
95 7 73 89 20 74 52
95 7 73 5 19 44 20
95 7 40 35 60 93 67
95 45 92 41 13 1 84
76 61 93 81 27 46 83
76 79 91 0 19 41 1
This example specifies two columns to sort by: columns 1 and7. This tells sortrows to sort by column 1 first,and then for any rows with equal values in column 1, to sort by column7:
D = sortrows(A,[1 7])
D =
76 79 91 0 19 41 1
76 61 93 81 27 46 83
95 7 73 5 19 44 20
95 7 73 89 20 74 52
95 7 40 35 60 93 67
95 45 92 41 13 1 84Sort the matrix using the values in column 4 this time and inreverse order:
E = sortrows(A, -4)
E =
95 7 73 89 20 74 52
76 61 93 81 27 46 83
95 45 92 41 13 1 84
95 7 40 35 60 93 67
95 7 73 5 19 44 20
76 79 91 0 19 41 1
حالا اینو جایگزین کردم این پیغام رو میده :
??? Undefined function or method 'rows' for input arguments of type 'double'.
Error in ==> pro at 20
while( rows(ij)~=0)