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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!