I have a bunch of nested 'if' statements in one another, and I can't get them to flow the way I want them. I have an if statement, and if it is met, I run a uniqueness test (myuniquetest), and if that shows that my condition gives a unique result, I want to log it and go on. I've got that part all figured out However, if the first condition does not give a unique result, I want to continue with the rest of the elseif statements to see if the subsequent ones give a unique result. (I have a total of 8 elseif statements within this code, but I imagine the methodology iwll be the same.) My code looks something like this:
if edgedouble(y0-1, x0) == 1 && (y0-1)>=y1 && (y0-1)<=y2;
testpt = [y0-1, x0];
uni = myuniquetest(testpt, mypoints);
if uni ==1;
k = k+1;
mypoints{1,k} = testpt;
mypoints = testmypoints(mypoints, edgedouble, x1, x2, y1, y2);
end
elseif edgedouble(y0-1, x0+1) ==1 && (y0-1)>=y1 && (y0-1)<=y2 && ...
(x0+1)>=x1 && (x0+1)<=x2;
testpt = [y0-1, x0+1];
uni = myuniquetest(testpt, mypoints);
if uni ==1;
k = k+1;
mypoints{1,k} = testpt;
mypoints = testmypoints(mypoints, edgedouble, x1, x2, y1, y2);
end
etc....
end
What I want it to do is, if uni==0, continue onto the elseif(condition2) (and so on), but currently it just stops. I tried adding in a while statement after each of the embedded 'if' statements so they looked like this:
if uni ==1;
(log my values, move on)
end
while uni==0
continue
end
However, it crashed the rest of my code, and subsequently Matlab. Is there an easier way to do this?
The code for the uniqueness function is as follows:
function[uni] = myuniquetest(testpoint, mypoints)
mysize = size(mypoints);
for w = 1:mysize(2);
myt = isequal(testpoint, mypoints{1,w});
if myt == 1;
uni = 0;
break
else
uni = 1;
end
end
All of this works when the conditions are met and are unique, but it doesn't work and just stops when the condition is met but there is not uniqueness.
Thanks!!