problem in return code

3 Ansichten (letzte 30 Tage)
Tariq Nazzal
Tariq Nazzal am 26 Sep. 2012
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 Kommentare
Jan
Jan am 26 Sep. 2012
What does this mean: "return to start of function"?
Tariq Nazzal
Tariq Nazzal am 27 Sep. 2012
I mean go to start of program and rerun the program again and again

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Babak
Babak am 26 Sep. 2012
"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 Kommentare
Babak
Babak am 27 Sep. 2012
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 am 27 Sep. 2012
thanks to you, I'm try it and it the correct answer, thanks you again...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 26 Sep. 2012
At first I suggest to simplify the computations:
% per diff between a and b
perab = sum(xor(a(:), b(:)) ~= 0) / numel(a);
  3 Kommentare
Jan
Jan am 27 Sep. 2012
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 am 27 Sep. 2012
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

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by