フィルターのクリア

rows extraction in matrix depending on a column value

1 回表示 (過去 30 日間)
PK
PK 2013 年 6 月 28 日
コメント済み: Saumy Tewari 2021 年 1 月 27 日
I have a 50x50 matrix and n that the last row has 0,1,2 at different locations ie., 0 n 10 rows,1 n 20 rows ad 2 in 20 rows, so depending on the column value how can i extract all rows containing 0 at 50th column and save them in to a single variable
  2 件のコメント
Sean de Wolski
Sean de Wolski 2013 年 6 月 28 日
A small example of your matrix and expected results would make this much easier to grasp.
PK
PK 2013 年 6 月 28 日
編集済み: PK 2013 年 6 月 28 日
@Sean de Wolski A=[1 2 3 0; 1 2 5 0;5 8 6 1;6 8 7 0;5 4 7 2;6 5 8 0] so in this there are 6 rows and depending on fourth element of the row all the rows containing same number are to be pinned up to a single variable ie.,rows 1,2,4,6 are to be stored to a single variable and row 3 to another and row 5 to another.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2013 年 6 月 28 日
Try this:
% Generate sample data
A=[...
1 2 3 0;
1 2 5 0;
5 8 6 1;
6 8 7 0;
5 4 7 2;
6 5 8 0]
% Get last column
lastColumn = A(:, end);
% Get zeros
A0 = A(lastColumn == 0, :)
% Get zeros
A1 = A(lastColumn == 1, :)
% Get zeros
A2 = A(lastColumn == 2, :)
In the command window:
A =
1 2 3 0
1 2 5 0
5 8 6 1
6 8 7 0
5 4 7 2
6 5 8 0
A0 =
1 2 3 0
1 2 5 0
6 8 7 0
6 5 8 0
A1 =
5 8 6 1
A2 =
5 4 7 2

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by