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

5 次查看(过去 30 天)
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?

采纳的回答

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
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 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by