필터 지우기
필터 지우기

how can I cancel repeated results?

조회 수: 2 (최근 30일)
frwmetric
frwmetric 2013년 5월 19일
Hi
how can I cancel repeated results??? here a function result st
s =
-2 2 -1
s =
-2 -2 1
s =
-2 2 -1
s =
0 0 3
s =
0 0 -3
s =
0 0 3
s =
0 0 -3
here s in the for loop
and unique(s,'rows') doesn't work
I know, because of the 'rows', not change anything here but I want to save same variables in the row...
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 19일
What do you mean by cancel repeated result. s is a 1x3 array, each step the old s is erased by the new s. post your for loop and explain what is the expected result
frwmetric
frwmetric 2013년 5월 19일
for example here as you see, 0 0 3 is written two times... in my expectation just one time... here is a a part of my function...
M = [1 1 1; 1 1 -1; 1 -1 1; 1 -1 -1; -1 1 1; -1 1 -1; -1 -1 1; -1 -1 -1];
rowM=zeros(1,3);
for p=1:numel(M)/3
rowM(:)=M(p,:);
s=(rowM.*vector)

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 5월 19일
s = bsxfun(@times,M,vector);
sout = unique(s,'rows','stable');

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 19일
편집: Azzi Abdelmalek 2013년 5월 19일
If
s ={{-2 2 -1},{-2 -2 1},{-2 2 -1},{0 0 3},{0 0 -3},{0 0 3},{0 0 -3}}
Then
out=unique(cell2mat(cellfun(@cell2mat,s','un',0)),'rows')
Or if
s ={-2 2 -1;-2 -2 1,;-2 2 -1;0 0 3;0 0 -3;0 0 3;0 0 -3}
Then
out=unique(cell2mat(s),'rows')

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 19일
M = [1 1 1; 1 1 -1; 1 -1 1; 1 -1 -1; -1 1 1; -1 1 -1; -1 -1 1; -1 -1 -1];
rowM=zeros(1,3);
vector=[1 0 1]
for p=1:size(M,1)
rowM(:)=M(p,:);
s{p,1}=(rowM.*vector)
end
out=unique(cell2mat(s),'rows')

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by