Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Dean Ranmar
Dean Ranmar le 20 Déc 2016
Modifié(e) : Jan le 26 Déc 2016
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 commentaire
Dean Ranmar
Dean Ranmar le 20 Déc 2016
Of course "ndx" is a true/false matrix of same dimension as matrix Amat.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 20 Déc 2016
Modifié(e) : Jan le 26 Déc 2016
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 commentaires
Dean Ranmar
Dean Ranmar le 20 Déc 2016
Thanks! The key is the ind2sub function. Excellent.
Dean Ranmar
Dean Ranmar le 20 Déc 2016
Actually, it should be sub2ind, not ind2sub. Thanks again. BTW, I should have neat rather than elegant and your solution is neat.

Connectez-vous pour commenter.

Plus de réponses (1)

Mischa Kim
Mischa Kim le 20 Déc 2016
Would this do the trick?
Adx = Amat(Amat(:)>THR(:))
  4 commentaires
Dean Ranmar
Dean Ranmar le 20 Déc 2016
sorry! I switched the index names on you: ndr == rdx and ndc == rdc.
Dean Ranmar
Dean Ranmar le 20 Déc 2016
ndc == cdx

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by