필터 지우기
필터 지우기

How do I combine two index vectors to form a 2D index matrix?

조회 수: 4 (최근 30일)
Dean Ranmar
Dean Ranmar 2016년 12월 20일
편집: Jan 2016년 12월 26일
I have two methods for identifying which elements in a matrix have certain properties (e.g.; exceed a threshold).
ndx = Amat > THR; % matrix of threshold crossing locations
and:
[rdx, cdx] = find(Amat>THR); % vectors of threshold crossing locations
that I use for two different purposes [and actually apply to different matrices.] Results from the two methods are compared eventually. I'd like to take the two vectors (rdx, cdx) and convert them to a matrix so I can do an operation such as:
Adx = Amat(ndx); % matrix of threshold crossing amplitudes
which is done for the former case. I'm sure there's a simple way to take the two vectors and combine them to produce "pointer" matrix "ndx," but I haven't found it.
Help?
  댓글 수: 1
Dean Ranmar
Dean Ranmar 2016년 12월 20일
Of course "ndx" is a true/false matrix of same dimension as matrix Amat.

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

채택된 답변

Jan
Jan 2016년 12월 20일
편집: Jan 2016년 12월 26일
Does not look elegant:
[rdx, cdx] = find(Amat > THR);
Index = sub2ind(size(Amat), rdx, cdx); % [EDITED, was ind2sub...]
ndx = false(size(Amat));
ndx(Index) = true;
  댓글 수: 2
Dean Ranmar
Dean Ranmar 2016년 12월 20일
Thanks! The key is the ind2sub function. Excellent.
Dean Ranmar
Dean Ranmar 2016년 12월 20일
Actually, it should be sub2ind, not ind2sub. Thanks again. BTW, I should have neat rather than elegant and your solution is neat.

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

추가 답변 (1개)

Mischa Kim
Mischa Kim 2016년 12월 20일
Would this do the trick?
Adx = Amat(Amat(:)>THR(:))
  댓글 수: 4
Dean Ranmar
Dean Ranmar 2016년 12월 20일
sorry! I switched the index names on you: ndr == rdx and ndc == rdc.

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

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by