problem in return code

2 次查看(过去 30 天)
Tariq Nazzal
Tariq Nazzal 2012-9-26
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 个评论
Jan
Jan 2012-9-26
What does this mean: "return to start of function"?
Tariq Nazzal
Tariq Nazzal 2012-9-27
I mean go to start of program and rerun the program again and again

请先登录,再进行评论。

采纳的回答

Babak
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
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
Tariq Nazzal
Tariq Nazzal 2012-9-27
thanks to you, I'm try it and it the correct answer, thanks you again...

请先登录,再进行评论。

更多回答(1 个)

Jan
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
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.
Tariq Nazzal
Tariq Nazzal 2012-9-27
Other friends answer the problem by calling the function again , your question is true, but the picture is always refresh and refresh every time from device sending the picture to my path folder , and delete last picture from the folder, and saving new picture with the name of deleted picture.
thanks to you

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by