Debug this: for loop

Hi, I have a problem with for loop in my case
for i = 1:P
SrJasnosc(i) = props2(i).MeanIntensity;
end
and next operation is
I = find(SrJasnosc > 400);
when those two parts is contain in funtion to analize series of pictures matlab give me an error:
??? Undefined function or variable "SrJasnosc".
Error in ==> srednia at 18
I = find(SrJasnosc > 400);
when I put it to command window to check on one picture is ok work fine, but otherwise its crush by error, after 3 hours of thinking on it I give up, please help, sorry for bad english.
code for function :
function out = srednia(poOdj, IMy)
[O P] = bwlabel(poOdj);
props2 = regionprops(O,IMy,'MeanIntensity');
for i = 1:P SrJasnosc(i) = props2(i).MeanIntensity; end
I = find(SrJasnosc > 400);
out = ismember(O, I);

답변 (3개)

Matt Tearle
Matt Tearle 2011년 2월 23일

1 개 추천

Quick diagnostic: display the value of P (after it's returned by bwlabel)
Jan
Jan 2011년 2월 23일

1 개 추천

Btw: This can be done more efficiently:
for i = 1:P
SrJasnosc(i) = props2(i).MeanIntensity;
end
==>
SrJasnosc = [props2.MeanIntensity];
This method defines SrJasnosc even if props2 is an empty struct as long as it has the needed field.
gck
gck 2011년 2월 23일

0 개 추천

Its done, problem was the value of P, sometimes pictures are empty so in that situation P is < 1 so loop never start and "SrJasnosc" not existed, before the loop I put code "SrJasnosc = zeros(1,P);" and this is solve the problem.
Thanks for help and quick ansver !

댓글 수: 2

Matt Tearle
Matt Tearle 2011년 2월 23일
Yup, that's what I was guessing
Walter Roberson
Walter Roberson 2011년 2월 23일
Please Accept Matt's answer.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

gck
2011년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by