필터 지우기
필터 지우기

Splitting a matrix into smaller matrices...

조회 수: 2 (최근 30일)
Doron
Doron 2012년 2월 20일
I have a matrix 1000x3 matrix P which can be generated with the following code: (I call the columns of P: X, Y and Z)
P = [];
for X = 0.1:.1:1;
for Y = 0.01:.01:1;
Z = Y^2 + X;
P = vertcat(P, [X, Y, Z]);
end
end
I now want to create a matrix which contains all of the rows for which X = 0.5, say.
(This will be a 100x3 matrix in this example)
How do I do this?
Many thanks
D Howard

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 20일
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 2월 20일
Use unique() more directly.
[PU, PI, PJ] = unique(P(:,1));
PUC = length(PU);
for i = 1 : PUC
Q{i} = P(PJ == i, :);
end
Notice no floating point comparisons were used.
Doron
Doron 2012년 2월 20일
Thanks for this tip

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by