Splitting a matrix into smaller matrices...

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 日

0 投票

3 件のコメント

Doron
Doron 2012 年 2 月 20 日
Thanks Walter,
Will this ever be an issue when I am running a code which explicitly successively goes through the unique values at the immediately previous step?
What I mean to say is, my code will be going through values directly from the matrix, rather than some other calculations:
typically:
PU = unique(P(:,1))
PUC = size(PU, 1)
for i = 1:PUC
x = PU(i)
Q{i} = P( P(:, 1) == x)
end
Thanks again
D Howard
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 件)

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by