How to ignore values in a matrix that is out of bound when performing column 'find' in an array?
Afficher commentaires plus anciens
Z is a 1024X1024 matrix containing negative value in some pixels.
For each pixel in Z, I need to find the column from an array 0,5,10,15,20,25,30,35,40; Because of out of bound values existing in Z matrix, I get this error 'Subscript indices must either be real positive integers or logicals.' How do I set all the negative values in matrix Z to '0' or is there a way to get around this problem? Below is the code.
m=1024;
n=1024;
Th = (0,5,10,15,20,25,30,35,40);
i=1:length(Th)
ratioAB(:,:,i)=A./B % A and B are matrices for each Th
RF=ones(m,n);
for i=1:m
for j=1:n
Z2=Z(i,round(j));
col = find(Th > Z2,1,'first')-[1 0]
RF(i,j)= diff(cat(3,ratioAB(i,j,col)),[],3)/diff(Th(col))*(Z2 Th(col(1)))+ratioAB(i,j,col(1));
end
end
2 commentaires
Image Analyst
le 21 Août 2012
Modifié(e) : Image Analyst
le 21 Août 2012
Lots of syntax errors, like in the definition of Th and RF. Plus what's with the definition of col? You're defining it as a scalar minus a 1 by 2 array. That's not a column number like you said you want.
Yun Inn
le 22 Août 2012
Réponse acceptée
Plus de réponses (1)
Azzi Abdelmalek
le 21 Août 2012
Modifié(e) : Azzi Abdelmalek
le 21 Août 2012
Z(find(Z<0))=0
1 commentaire
Matt Fig
le 21 Août 2012
Or just:
Z(Z<0) = 0
No need for FIND...
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!