3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

論理インデックスを用いて行列の条件を満たす行(列)を取り出す。

Last updated at Posted at 2012-03-16

matrixの一列目がindex1, 二列目がindex2の値をとる行を取り出したいとき。

一行でもかけます。

logIndex1 = (matrix(:,1) == index1) & (matrix(:,2) == index2);
%論理インデックスの種を作る。

logIndex2 = repmat(logIndex1, 1, size(matrix,2)) 
% ここで一行の論理インデックスをmatrixのサイズと合わせる。

row = matrix(logIndex2);
%最後に1の部分だけを抽出。
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?