필터 지우기
필터 지우기

logical indexing please help

조회 수: 2 (최근 30일)
Saad
Saad 2014년 7월 23일
편집: Julia 2014년 7월 23일
Hey guys,
I would really appreciate your help in this.
I have a matrix of logical (i.e. for each row I have a lot of ones and zeros). The matrix is (100 x 100).
Now for each row (say first row) I would like to select the "one" element. Then I would like to compare the logical of each cell in the first row with the logical of other cells in the following rows. Then I would like to select the cells in the (other) rows that have similar logical expression with the cells of the first row i.e. (1,1) and ignore (1,0) or (0.0).
At the end, instead of having a matrix of (100 x100) say:
A=[ 1, 0 , 1,0 , 0....; 0, 1; 0; 1];
I would get a new (smaller) matrix A_new that only have elements that have similar logical expression that the first row of the matrix A: A_new= [ (1,1) , (1,1) ; ...];
I would really appreciate your help on this one. Thank you
S
  댓글 수: 1
Sagar Damle
Sagar Damle 2014년 7월 23일
Can you provide an example for your question along with desired answer to better understand it (using a small matrix) ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Julia
Julia 2014년 7월 23일
편집: Julia 2014년 7월 23일
You could use the find() command.
find(A>0)
This gets you the index of every value of A which is greater than zero.
A =
1 1 0 0 1 1
0 0 1 1 0 1
1 0 1 0 1 0
1 0 0 0 0 1
>> find(A>0)
ans =
1
3
4
5
10
11
14
17
19
21
22
24
Matlab counts as follows: (1,1),(2,1),(3,1),(4,1),(1,2),(2,2) etc to (n,n)
First the first column, then the second etc.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by