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에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by