How to delete repeated column in this matrix?

조회 수: 23 (최근 30일)
Matlab111
Matlab111 2015년 1월 30일
편집: Matlab111 2015년 1월 30일
a= [6.7747 15.1502 126.0000
67.9227 33.3699 74.0000
54.9636 40.7709 74.0000
102.5013 144.4162 44.0000
67.9227 33.3699 74.0000
54.9636 40.7709 74.0000];
i should not get the repeated values and i should get like this.
b=[6.7747 15.1502 126.0000
67.9227 33.3699 74.0000
54.9636 40.7709 74.0000
102.5013 144.4162 44.0000];
  댓글 수: 4
Niels
Niels 2015년 1월 30일
I believe he refers to the fact that a matrix consist of rows and columns and that your example is, in contrast to what you state, referring to duplicate rows instead of columns ;)
Matlab111
Matlab111 2015년 1월 30일
ya that's right it's not a matrix it's a value that's consist three variables like this
'x' y z
[67.9227 33.3699 74.0000];
but i'm considering only rows not columns in above my example.

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

채택된 답변

Niels
Niels 2015년 1월 30일
b = unique(a,'rows','stable');
b =
6.7747 15.1502 126
67.9227 33.3699 74
54.9636 40.7709 74
102.5013 144.4162 44
That should do it.
  댓글 수: 8
Niels
Niels 2015년 1월 30일
If you know beforehand how many rows you will obtain, you could do something like this:
allRows = zeros(N,3); % put this before line 308 where your loop starts. N is the number of rows you will expect.
Then replace your line b = S_nodes(sort(x),:); with
allRows(i,:) = S_nodes;
And finally place your uniqueness check after line 325 (where the loop ends):
b = unique(allRows,'rows','stable');
disp(b);
or
[~,x,~] = unique(S_nodes,'rows','first');
b = S_nodes(sort(x),:);
disp(b);
If you don't know how many rows you will obtain, you can do it in a slightly more dirty way:
allRows = []; % put this before line 308 where your loop starts. N is the number of rows you will expect.
And in your loop:
allRows(end+1,:) = S_nodes;
The rest can be done in the same fashion as above.
This should be sufficient to get you started.
Matlab111
Matlab111 2015년 1월 30일
편집: Matlab111 2015년 1월 30일
ya Thank you i'm getting...

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

추가 답변 (0개)

카테고리

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