How to find position of value in matrix and write as another matrix
조회 수: 4 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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개)
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 Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!