my code is getting skipped
古いコメントを表示
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 件のコメント
Joseph Cheng
2014 年 4 月 7 日
I would suggest that you step through using the debugger.
dpb
2014 年 4 月 7 日
Indeed...as written, 3: will always execute whereas there'll be nothing shown in 2: if the average is outside the range [10 50].
As a comment, I'd compute and save the mean early on in the code to not have to recompute it a half-dozen times or more...
More than likely if there is a coding problem it's either--
a) the data isn't what you think and the condition isn't satisfied, or
b) probably even more likely, the problem is in something you haven't shown.
Agree w/ the other respondent -- use the debugger thru the entire code for a case that you think is troublesome.
nida
2014 年 4 月 7 日
nida
2014 年 4 月 8 日
回答 (2 件)
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 件のコメント
nida
2014 年 4 月 7 日
Image Analyst
2014 年 4 月 7 日
Attach your m-file and image (or else change your code to use a standard demo image).
nida
2014 年 4 月 7 日
Image Analyst
2014 年 4 月 7 日
編集済み: Image Analyst
2014 年 4 月 7 日
The code you attached doesn't run. For one thing, the bargraphnn functions are not included. Plus you say "sometimes i want all of them to run" - well, when is that? As you have it now, only one if block runs depending on what the mean is.
nida
2014 年 4 月 7 日
Image Analyst
2014 年 4 月 7 日
Answer this:
you say "sometimes i want all of them to run" - well, when is that? As you have it now, only one if block runs depending on what the mean is.
nida
2014 年 4 月 7 日
Image Analyst
2014 年 4 月 7 日
Well, get rid of all the "if" statements! Just call bargraph0, etc. and don't check what the mean is - just run it regardless of what the mean is.
Image Analyst
2014 年 4 月 7 日
When do you want to call bargraph0? All the time or only when (meangl>=30 && meangl<=40) ???
You can't call it all the time and also only when the mean is in a certain range . That does not make sense.
Image Analyst
2014 年 4 月 7 日
What's that image about? If you're wanting to measure color or something between different images you better be sure you have an color calibrated system. I don't see any color chart in there.
nida
2014 年 4 月 7 日
Image Analyst
2014 年 4 月 7 日
If you change the exposure, or use a flash, on your camera then you could get different brightnesses even though the dirt did not change one bit.
nida
2014 年 4 月 7 日
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
2014 年 4 月 8 日
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'
カテゴリ
ヘルプ センター および File Exchange で Historical Contests についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!