필터 지우기
필터 지우기

my code is getting skipped

조회 수: 6 (최근 30일)
nida
nida 2014년 4월 7일
댓글: nida 2014년 4월 8일
my m file runs properly halfway but it skips(does not display output image)for some codes
it does not show any error.this is my code it does not run altogether.if i remove 3rd part 2nd executes,or else 2nd does not.1 does sometimes i want all of them to run(this is half code of my m-file)
1st:
g=rgb2gray(Image)
figure,surf(double(g),'edgecolor','none')
%axis([0 columns 0 rows min(double(g(:))) max(double(g(:)))])
colormap hot
2: im=(Image)
mean(im(:))
if mean(im(:))>=10 & mean(im(:))<=47
bargred0
end
if mean(im(:))>=47 & mean(im(:))<=50
bargred0
end
3: a=mean(im(:))
r=.5
t=1:1:10
x1=100*(1+r).^t
x2=a*(1+r).^t
plot(x1)
hold on
plot(x2,'--')
xlabel('Days')
ylabel('Growth Rate')
legend('General','Acquired')
  댓글 수: 4
nida
nida 2014년 4월 7일
nida
nida 2014년 4월 8일
ok,i set a breakpoint , and using steps went through the code, everything worked but,when a first figure displays it gets replaced by next figure,thereby showing the first and last figures only.

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

답변 (2개)

Image Analyst
Image Analyst 2014년 4월 7일
편집: Image Analyst 2014년 4월 7일
After you view this http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ and use what you learn, you will know why it's skipping past some lines of code. By the way, you need to change these lines to:
meanGL = mean2(im);
if meanGL >= 10 && meanGL <= 50
bargred0
end
Use mean2() instead of mean(), call it only once, use && instead of &, and combine two ifs into one.
  댓글 수: 17
Image Analyst
Image Analyst 2014년 4월 7일
If you want to classify what kind of dirt it is and you say that a gray level of 80 means it's black loam, then what happens when you come tomorrow when it's cloudy and the gray level is only 50? Or you come again next month and it's bright and sunny and the gray level is 150? Are you going to call it beach sand instead of black loam because it's brighter? It's the same dirt - you should not classify it as something different. It just changed because of the exposure or lighting, but it's the same dirt.
nida
nida 2014년 4월 8일
ok,but what about my problem

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


Sagar Damle
Sagar Damle 2014년 4월 7일
if mean(im(:))>=10 & mean(im(:))<=47 :- Second 'if'
if mean(im(:))>=47 & mean(im(:))<=50 :- Third 'if'
I think,you are getting problem when mean = 47. This is because when mean = 47,second 'if' will be executed and third will be ignored.You can try this -
if mean(im(:))>=10 & mean(im(:))<=47 :- Second 'if'
if mean(im(:))>47 & mean(im(:))<=50 :- Third 'if'

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by