problem in return code
2 次查看(过去 30 天)
显示 更早的评论
Hi, I worked a program to my final project in university; but there a problem in my m file... I need to return to start of my program in one case, but i can't... my program is:
function out = firstecg(x)
a=imread(x);
b=imread('normal.png');
a=rgb2gray(a);
b=rgb2gray(b);
a=im2bw(a);
b=im2bw(b);
%per diff between a and b
w=0;
const=size(a);
row=const(1);
column=const(2);
constant=row*column;
for i=1:row
for j=1:column
y=xor(a(i,j),b(i,j));
if y~=0
w=w+1;
end
end
end
perab=w/constant;
perab;
perno1=0.0023;
perno2=0.0040;
if ((0.0005>= perab)& (perab>= 0))
disp('no problem')
return %my problem is here
else
.
.
.
end %end of my program
when I run the program and in a case of return ... the result is just "no problem" , I need to return to a start of function but i can't, "the Matlab is not applied return in any case and that is a problem"
please help my
2 个评论
采纳的回答
Babak
2012-9-26
"return" command, ends the execution of the code.
"return" does not mean that the code is going to start from the beginning of the function and start running it again and again....
3 个评论
Babak
2012-9-27
Change that block of your code to this and see if it works:
if ((0.0005>= perab)& (perab>= 0))
disp('no problem')
% Here is where you need to call this function again
% You need to set the input and output arguments of the next
% line depending on your case
out = firstecg(x)
else
更多回答(1 个)
Jan
2012-9-26
At first I suggest to simplify the computations:
% per diff between a and b
perab = sum(xor(a(:), b(:)) ~= 0) / numel(a);
3 个评论
Jan
2012-9-27
Well, I do not have any clue, why you use "return", when you want a loop.
perab = 0;
while 0 <= perab & perab <= 0.0005
... Her is your program
end
But what do you expect? You read in the same picture files and get the same results in each iteration. Therefore it is not clear, what you want to achieve.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!