Matlab - Continue to next elseif in nested if statements -


i have bunch of nested 'if' statements in 1 another, , can't them flow way want them. have if statement, , if met, run uniqueness test (myuniquetest), , if shows condition gives unique result, want log , go on. i've got part figured out however, if first condition not give unique result, want continue rest of elseif statements see if subsequent ones give unique result. (i have total of 8 elseif statements within code, imagine methodology iwll same.) code looks 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 want is, if uni==0, continue onto elseif(condition2) (and on), stops. tried adding in while statement after each of embedded 'if' statements looked this:

    if uni ==1;     (log values, move on)     end while uni==0 continue end 

however, crashed rest of code, , subsequently matlab. there easier way this?

the code uniqueness function follows:

function[uni] = myuniquetest(testpoint, mypoints) mysize = size(mypoints); w = 1:mysize(2); myt = isequal(testpoint, mypoints{1,w}); if myt == 1; uni = 0; break else uni = 1; end end 

all of works when conditions met , unique, doesn't work , stops when condition met there not uniqueness.

thanks!!

what recommend place of boolean conditions individual elements logical array, of possible test points in array. after, iterate on of conditions corresponding test points , use testmypoints script check see if uni = 1 or uni = 0. keep iterating on of conditions , corresponding test points until uni = 1, can break out of loop.

as such, make logical array called conditions this:

conditions = [edgedouble(y0-1, x0) == 1 && (y0-1)>=y1 && (y0-1)<=y2;               edgedouble(y0-1, x0+1) ==1 && (y0-1)>=y1 && (y0-1)<=y2 && (x0+1)>=x1 && (x0+1)<=x2;               ...               ...]; 

place each condition want check inside logical array. next, place corresponding test points each condition inside array. let's call testpoints:

testpoints = [y0-1 x0;               y0-1 x0-1;               ...               ...]; 

testpoints 2d array, each row consists of test point matches condition in corresponding position in conditions. now, have iterate through each condition , corresponding point until hit uni = 1. if uni = 0, keep looping , check other conditions until uni = 1, or if run out of conditions check, loop end , won't results logged.

without further ado:

for idx = 1 : numel(conditions)     if conditions(idx)         testpt = testpoints(idx,:);         uni = myuniquetest(testpt, mypoints);          if uni == 1             k = k + 1;             mypoints{1,k} = testpt;             mypoints = testmypoints(mypoints, edgedouble, x1, x2, y1, y2);             break;         end     end end 

let's walk through code slowly, first, check see whether particular condition true. if is, let's corresponding test point corresponds position, check myuniquetest. should uni == 1, run code happens when uni == 1 (truthfully, don't understand you're doing here, if works.... ok then!). once happens, break out of loop , results logged. if uni == 0, our condition isn't satisfied, should proceed , check other conditions.


hope helps!


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -