Saturday 15 January 2011

Matlab: How I can make this transformation on the matrix A? -



Matlab: How I can make this transformation on the matrix A? -

i have matrix a 4x10000, want utilize find matrix c.

i'll simplify problem simple example:

from matrix a

20 4 4 74 20 20 36 1 1 11 36 36 77 1 1 15 77 77 3 4 2 6 7 8

i want, first, find intermediate entity b:

2 3 4 6 7 8 [20 36 77] 0 1 0 0 1 1 3 [4 1 1] 1 0 1 0 0 0 2 [74 11 15] 0 0 0 1 0 0 1

we set 1 if corresponding value of first line , vector on left, made ​​a column in matrix a.

the lastly column of entity b sum of 1 of each line.

at end want matrix c, consisting of vectors left in entity b, if sum of 1 greater or equal 2.

for example:

20 4 c = 36 1 77 1

n.b: problem, utilize matrix a 4x10000

see if works -

%// need replace not available in old version of matlab: %// [unqcols,~,col_match] = unique(a(1:end-1,:).','rows','stable') %//' a1 = a(1:end-1,:).'; %//' [unqmat_notinorder,row_ind,labels] = unique(a1,'rows'); [tmp_sortedval,ordered_ind] = sort(row_ind); unqcols = unqmat_notinorder(ordered_ind,:); [tmp_matches,col_match] = ismember(labels,ordered_ind); %// or utilize - "[tmp2,col_match] = ismember(a1,out,'rows');" c = unqcols(sum(bsxfun(@eq,col_match,1:max(col_match)),1)>=2,:).'; %//' %// or utilize - "c = out(accumarray(col_match,ones(1,numel(col_match)))>=2,:).'"

matlab matrix

No comments:

Post a Comment