yellow = [300 287 301 400 211 399 412 312 390 412];
red = [240 259 302 311 210 402 390 298 347 380];
black = [ 210 230 213 210 220 208 290 300 201 201];
big_yellow = [289 289 300 402 251 389 422 332 360 422];
big_red = [210 229 300 301 200 340 350 290 317 320];
big_black = [226 220 253 218 260 228 380 300 221 211];
X=[small_yellow small_red small_black big_yellow big_red big_black]';
nsubj=10;
nlevelsSize=2;
nlevelsColor=3;
nmales=5;
nfemales=5;
Subj=repmat(1:nsubj,1,nlevelsSize*nlevelsColor)';
sizesmall=repmat({'small'},1,nlevelsColor*nsubj)';
sizebig=repmat({'big'}, 1,nlevelsColor*nsubj)';
Size= [sizesmall' sizebig']';
Colyellow=repmat({'yellow'},nsubj,1);
Colred=repmat({'red'},nsubj,1);
Colblack=repmat({'black'},nsubj,1);
Color= [Colyellow' Colred' Colblack' Colyellow' Colred' Colblack']';
male= repmat({'m'},1,nmales)';
female= repmat({'f'},1,nfemales)';
Gender=repmat([male; female]',1,nlevelsSize*nlevelsColor)';
nesting=[0 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 1 0 ];
modeling=[1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1; ... %main effects
1 1 0 0; 1 0 1 0; 1 0 0 1 ; ... %first IV interactions
0 1 1 0; 0 1 0 1;... %second IV interactions
1 1 1 0]; % all interactions among IVs apart the nested one
[p table stats terms]=anovan(X,{Size Color Gender Subj }, 'random',4, ...
'model',modeling,'nested',nesting,'varnames',{'Size' 'Color' 'Gender' ...
'Subj'});