matlab - How to call multiple functions using if statement? -


i want perform following function using if statement has variables in it. consider 3 cell arrays a, b , c of size 16 x 16 each.for example i'm taking 4 x 4 cell arrays.

 = b c d            b = c b d          c = 0 2 1 3                     d c b                b d c              3 2 3 1                    c b d                b d              2 1 0 1                           b d c                d a c              3 2 2 2 

with respect values in c need perform functions on , b follows,

if c == 0    out = b; elseif c == 1    out = xx(a,b); elseif c == 2    out = complement (b); elseif c == 3    out = nx(a,b); end  

here complement, xx , nx functions called. tried following code somehow 'if' statement making hard results. i've defined functions code used perform above operation.

   i=1:1:16       j=1:1:16          if c(i,j) == 0             o(i,j) = b(i,j);          elseif c(i,j) == 1                o(i,j) = xx(a(i,j),b(i,j));          elseif c(i,j) == 2                o(i,j) = complement(b(i,j));            elseif c(i,j) == 3                o(i,j) = nx(i,j);           end        end end 

the function complement follows

  function [q]=complement(p)   [w1,w2] = size(p);   q = zeros(w1,w2);   p1 = cell2mat(p)   i=1:1:w1      j=1:1:w2          if p1 == 'a'            q(i,j) == 'd';          elseif p1 == 'b'                q(i,j) == 'c';          elseif p1 == 'c'                q(i,j) == 'b';          elseif p1 == 'd'                q(i,j) == 'a';          end  end  end 

the function xx follows

  function [q] = xx(t,p)   t = cell2mat(t);   p = cell2mat(p);    q(t == 'a'  & p == 'a') = 'a'; q(t == 'a'  & p == 'b') = 'b'; q(t == 'a'  & p == 'c') = 'c'; q(t == 'a'  & p == 'd') = 'd';   q(t == 'b'  & p == 'a') = 'b'; q(t == 'b'  & p == 'b') = 'a'; q(t == 'b'  & p == 'c') = 'd'; q(t == 'b'  & p == 'd') = 'c';   q(t == 'c'  & p == 'a') = 'c'; q(t == 'c'  & p == 'b') = 'd'; q(t == 'c'  & p == 'c') = 'a'; q(t == 'c'  & p == 'd') = 'b';   q(t == 'd'  & p == 'a') = 'd'; q(t == 'd'  & p == 'b') = 'c'; q(t == 'd'  & p == 'c') = 'b'; q(t == 'd'  & p == 'd') = 'a'; 

the function nx similar xx substitution differs. don't know i'm going wrong either in functions or in 'if' statement. when run code first if statement , 'first if statement' complement function alone getting executed, remaining functions not performed. thanks.

if a, b, c , o cell arrays, matlab not proceed c(i,j) == 0, since c(i,j) cell array , 0 numerical.

instead pop error (undefined function 'eq' input arguments of type 'cell').

if running first piece of code script, have check on workspace , see c , c(i,j) is.

if want keep a, b, c , o cell arrays, suggest using cell array element operators such c{i,j} == 0, o{i,j} = complement(b(i,j)) since b(i,j) cell output of complement function numerical.