Indexing multidimensional matrices using logical arrays
Afficher commentaires plus anciens
I want to efficiently find number in a multidimensional array that fall into
some category and do something to them,like in the code below:
nc=4;
mc=1000;
r1=normrnd(0,1,[nc,mc,n-1]);
for j=2:n
indexNeg(:,:)=r1(:,:,j)<0.5;
r1(:,:,j)=-r1(indexNeg,j);
end
here, I create a multidimensional array of random numbers and change sign of any number smaller than 0.5
I am getting this error Subscript indices must either be real positive integers or logicals.
How to properly use the logical index?
Réponse acceptée
Plus de réponses (2)
Andrei Bobrov
le 17 Déc 2013
Modifié(e) : Andrei Bobrov
le 17 Déc 2013
l = r1 < .5;
r1(l) = -r1(l);
On comment by Marco
r1 = abs(r1);
2 commentaires
Marco Pereira
le 17 Déc 2013
Modifié(e) : Marco Pereira
le 17 Déc 2013
Andrei Bobrov
le 17 Déc 2013
What you want?
Marco Pereira
le 17 Déc 2013
0 votes
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!