필터 지우기
필터 지우기

matrix

조회 수: 1 (최근 30일)
Khawaja Asim
Khawaja Asim 2011년 12월 20일
if i want to find the index of certain value in 2D matrix, how can I find that? e.g: I have a 300x300 matrix. There is a value 90096 in that matriz. I want to find its index. Please show me the code.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 12월 20일
A =[ 191 23 37 34 154
212 66 228 99 9
30 128 224 215 199
214 225 114 186 219
148 226 188 225 159];
a = 224;
[i1,j1] = find(abs(A-a) < 100*eps);
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 12월 20일
Yes! If you do not know for sure that the values are integral, then using exact comparisons will often fail.
Khawaja Asim
Khawaja Asim 2011년 12월 20일
thank you for answer.. Actually I have a matrix about 300x300 order app. It contains a lot of zero values and non-zero value. I want to find the index of min value other than zero. So I thought of a logic, I stored a matirx in another variable. then deleted all zeros from it. then got min value using "minimum=min(A). Now I wanted to find the index of this "minimum" from original matrix. I hope I thought of correct logic :-)

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

추가 답변 (2개)

Jim
Jim 2011년 12월 20일
you can use find command to know the index of values in matrix

C.J. Harris
C.J. Harris 2011년 12월 20일
Using find with two return parameters might make it easier.
[row, col] = find(matrix == 90096);
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 12월 20일
Probably the value in the matrix was not _exactly_ 90096
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Khawaja Asim
Khawaja Asim 2011년 12월 20일
ans given by andrei worked

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by