Try using a switch case statement
N = 72;
M = 72;
adj = zeros(N,M);
L = [10:7:M-13];
R = [16:7:M-7];
for N = 1:M
for i = 1:ceil((M-10)/15)
switch(N)
case {1}
adj(1,2:4)= 1;
case {2:4}
adj(N,(N+3))=1;
adj(N,(N+4))=1;
adj(N,(N+5))=1;
case {5:9}
adj(N,(N+5))=1;
adj(N,(N+6))=1;
adj(N,(N+7))=1;
case {L(i)}
adj(N,N+7)=1;
adj(N,N+8)=1;
case {R(i)}
adj(N,N+6)=1;
adj(N,N+7)=1;
otherwise
adj(N,N+6)=1;
adj(N,N+7)=1;
adj(N,N+8)=1;
end
end
end
This gives a slightly different answer to your code. Note that only the first satisfying case
will be triggered. So if both {5:9}
and {L(i)}
are true, only the {5:9}
case will be triggered.
Also, it may be just a typo, or me not understanding the wording, but you are writing R==L(i)
in your description but that doesn't appear in your code.
Edit:
From your comment below, it seems you want more than one elseif
or case
statement to be triggered at a time. In this case, neither a series of elseif
s or case
s will work. Simply replace all the elseif
s with separate, indivdiual if
statements, without any elseif
s. Just be aware that now any if
statement can trigger, including the ones you don't intend to. So you will have to look carefully at each condition.