Hi guys,
Is there any command like "unique" for matrices?
I have a major matrice (mother) , and that involve few minor matrices, some of are repeated randomly
i'm looking for a command for delete repeated ones and do something like unique ,
anybody knows how?

댓글 수: 3

madhan ravi
madhan ravi 2019년 4월 23일
Well without illustration it’s not clear , sounds like unique is what you need. Better an example with an explicit example would be great.
Andrei Bobrov
Andrei Bobrov 2019년 4월 23일
Please post an example of your matrix and what you want to receive.
thanks for your reply
see,
we have 3 matrices,
A=[1;2;3] ; B=[1;2;3] ; C=[4;5;6];
all of them are in another matrice (call it R)
R={A;B;C}
as you see A & B 's first column are the same,
i want to delete one of them (A or B) and the result must be like below:
R={A;C}

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2019년 4월 23일
편집: Stephen23 2019년 4월 23일

1 개 추천

A general solution that does not concatenate the data and works for any size arrays:
% Fake data:
A = [1;2;3];
B = [1;2;3];
C = [4;5;6];
R = {A;B;C}
% Method:
N = numel(R);
X = false(1,N);
for ii=2:N
Y=false;
for jj=1:ii-1
Y = Y || isequal(R{ii},R{jj});
end
X(ii) = Y;
end
R(X) = []

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 4월 23일

1 개 추천

A=[1;2;3];
C=[4;5;6];
M = [repmat(A,2,1);C];
out = reshape(unique(reshape(M,3,[])','rows','stable')',[],1);

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2016a

질문:

2019년 4월 23일

댓글:

2019년 4월 23일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by