How to find position of value in matrix and write as another matrix

2 ビュー (過去 30 日間)
Akmyrat
Akmyrat 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日
Lets say i have this matrix
A = [1 0;
0 0;
1 1;
0 1;
0 0]
Now i want to write the positions of line of value "1" in another matrix B. In A it should start from column1. answer should be like this
B=[1 3 3 4]
which is in column1 value"1" is at 1 and 3, and in column 2 value"1" is at line 3 and 4.

採用された回答

the cyclist
the cyclist 2014 年 8 月 13 日
編集済み: the cyclist 2014 年 8 月 13 日
[ii jj] = find(A);
B = ii';
Since you don't need the jj index, you can just do
[ii ~] = find(A);
B = ii';
instead.
  1 件のコメント
Akmyrat
Akmyrat 2014 年 8 月 13 日
thanks a lot cyclist...Same A matrix with one more column A=[1 0 0;0 0 1;1 1 0;0 1 0;0 0 0]. i want result to be like that B=[1 3 2 3 4], which is from top to down 1 and 3 position in !st column, 2 position in 3rd column, 3 and 4 position in 2nd column. can u help please.

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日
on Akmyrat's comment
[B,~] = find(A(:,[1 3 2]));
B = B';

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by