x=randperm(45); y=randperm(45); z=randperm(45); answerperson=x(y(z(22))) subject.id=1; subject.age=18; subject.hand=0; subject.gender=1; for i=1:5 for j=1:6 mat(i,j)=(i-1)*6+j; end end mat % build struct subject(1).id=51; subject(1).age=18; subject(1).hand=0;%0 is left hand.1 is right hand subject(1).gender=1;% 1 is male, 2 is female subject(1).data=[1:10]; subject(2).id=2; subject(2).age=19; subject(2).hand=1; subject(2).gender=2; subject(2).data=[2:8]; subject(3).id=33; subject(3).age=20; subject(3).hand=0; subject(3).gender=2; subject(3).data=[3:9]; subject(4).id=11; subject(4).age=21; subject(4).hand=1; subject(4).gender=2; subject(4).data=[11:17]; % sub(2,1).id=1; % sub(2,1).age=18; % sub(2,1).hand=1; % sub(2,1).gender=1; % % sub(2,2).id=2; % sub(2,2).age=19; % sub(2,2).hand=1; % sub(2,2).gender=2; % % sub(2,3).id=2; % sub(2,3).age=19; % sub(2,3).hand=1; % sub(2,3).gender=2; %% for, if, index,computation length(subject) count=0; for a=1:length(subject) if subject(a).gender==2; count=count+1; dataMean(count)=mean(subject(a).data) a end end dataMean % if id is random count=0; for a=1:length(subject) if subject(a).gender==2; count=count+1; dataMean(1,a)=subject(a).id; dataMean(2,a)=mean(subject(a).data); end end dataMean subject(1).id=51; subject(1).age=18; subject(1).hand=1; subject(1).gender=1; subject(1).data=[1:10]; subject(2).id=2; subject(2).age=19; subject(2).hand=1; subject(2).gender=2; subject(2).data=[2:8]; subject(3).id=33; subject(3).age=20; subject(3).hand=2; subject(3).gender=2; subject(3).data=[3:9]; animalsub.id=65; animalsub.data=rand(1,10); animalsub(2).id=79; animalsub(2).data=rand(1,7); allsub.human=subject; allsub.animal=animalsub; allsub(2).human=subject; allsub(2).animal=animalsub; allsub(2,1).human=subject; allsub(2,1).animal=animalsub; allsub(2,2).human=subject; allsub(2,2).animal=animalsub; allsub(2,1).animal(2).id allsub(1).animal(2).id allsub(2).animal(2).id allsub(3).animal(2).id allsub(4).animal(2).id days=['abc''xyz'] days=['abc','xyz'] words='my mom''s purse is purple' days={'Mon','Tue','Wed','Thur', 'Fri'};