find all indices in a matrix

조회 수: 1 (최근 30일)
Oday Shahadh
Oday Shahadh 2017년 1월 10일
댓글: Oday Shahadh 2017년 1월 10일
How can I find all indices in a matrix to include the zero and non-zero elements? .Thanks

채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 10일
find(ones(size(TheMatrix))
This is not typically useful. Instead you would normally use something like
[R, C] = ndgrid(1:size(TheMatrix,1), 1:size(TheMatrix,2));
and then R will contain row indices and C would contain column indices, so R(I,J) will always be I and C(I,J) will always be J. This is mostly used in a form such as
RC = [R(:), C(:)];
This can also be created as
[R, C] = ind2sub(size(TheMatrix), 1:numel(TheMatrix));
RC = [R(:), C(:)];
  댓글 수: 2
Oday Shahadh
Oday Shahadh 2017년 1월 10일
it works, thanks Walter
Oday Shahadh
Oday Shahadh 2017년 1월 10일
Dear Walter, how can I find the indices of the max. and min in the syntax
DDDD = accumarray(OrbNO,elev,[],@(x) max(x)-min(x), 0);

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by