indexing a set in an array

1 vue (au cours des 30 derniers jours)
Paul Gendron
Paul Gendron le 18 Jan 2021
Commenté : Paul Gendron le 22 Jan 2021
Dear users, Im trying to find a fast way to index a set of elements of an array that meet some criteria. For instance, Imagine that I have an array A=zeros(Nx,Ny) Nx=1000;Ny=1000. so A(k,l)=0 for all k,l<1000. Now I would like the set of indices, call them SET, that fullfill (k-ko)^2+(l-lo)^2<R^2 From which I can A(SET)=1. In this way with any given distance function I can build indicator functions for arbitrary sets.
  4 commentaires
Adam Danz
Adam Danz le 22 Jan 2021
Looks like Matt J hit the nail on the head. ✅
Paul Gendron
Paul Gendron le 22 Jan 2021
He really did, that deal() function is a gem and time saver. Thanks again Matt.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 19 Jan 2021
[k,l]=deal(1:1000);
SET=(k.'-k0).^2+(l-lo).^2 < R^2;
  1 commentaire
Paul Gendron
Paul Gendron le 21 Jan 2021
Just fantastic, thanks Matt!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Performance and Memory 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