How to ignore values in a matrix that is out of bound when performing column 'find' in an array?

조회 수: 2 (최근 30일)
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
Image Analyst
Image Analyst 2012년 8월 21일
편집: Image Analyst 2012년 8월 21일
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
Yun Inn 2012년 8월 22일
I have eight thicknesses, Th=0,5,10,15,20,25,30,35,40. For each of the Th, I have matrix, ratioAB.
Then, I have Z that is a 2D matrix consisting of pixels with different thicknesses. For each of the pixel, I need to find the correct ratioAB depending on the thickness. The result, RF, should be a matrix of ratioAB.
Because the Th range from 0 to 40, when I have negative value or value more than 40 in the Z matrix, I get the error 'Subscript indices must either be real positive integers or logicals.'
How do I fix the code?

댓글을 달려면 로그인하십시오.

채택된 답변

Matt Fig
Matt Fig 2012년 8월 21일

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 21일
편집: Azzi Abdelmalek 2012년 8월 21일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by