%% Profile Generator count=0; fflag=10; while fflag ==10 & count < 100 fflag=0; count=count+1; %% ini_day_dh if dh_i==1; ini_day_dh=randsample(dn_total-2,1); end if dh_i==2; ini_day_dh=randsample(dn_total-2,2); end if dh_i==3; ini_day_dh=randsample(dn_total-2,3); end %% position(s) of drug holidays if dh_i==1; position_dh_i=ini_day_dh:2+ini_day_dh; end if dh_i==2; position_dh_i=[ini_day_dh(1,1):2+ini_day_dh(1,1),ini_day_dh(2,1):2+ini_day_dh(2,1)]; end if dh_i==3; position_dh_i=[ini_day_dh(1,1):2+ini_day_dh(1,1),ini_day_dh(2,1):2+ini_day_dh(2,1),ini_day_dh(3,1):2+ini_day_dh(3,1)]; end %% possible positions of missed doses a=[1:1:150]; if dh_i~=0; a=[1:1:150]; b=setdiff(a,position_dh_i); end %% positions of missed doses if dh_i~=0; position_md_i=randsample(b,md_i); else position_md_i=randsample(a,md_i); end %% then generating timing deviates if dh_i==0; dn_taken=dn_total-(md_i); end if dh_i==1; dn_taken=dn_total-(md_i)-((dh_i*3)); end if dh_i==2; u=union(position_dh_i(1,1:3),position_dh_i(1,4:6)); dn_taken=dn_total-(md_i)-(length(u)); end if dh_i==3; u2=union(position_dh_i(1,1:3),position_dh_i(1,4:6)); uu=union(u2,position_dh_i(1,7:9)); dn_taken=dn_total-(md_i)-(length(uu)); end clear diff_tm_i for q=1:dn_taken; if rand()
0 fflag=10; end % when dh_1==1, discard NCMD occurring right before dh at least one point of time in the profile if dh_i==1; position_md_i_plus_1=position_md_i+1; combined_1_plus=horzcat(position_md_i_plus_1,position_dh_i); if length(strfind(diff(sort(combined_1_plus)),[0]))>0; fflag=10; end end % when dh_1==1, discard NCMD occurring right after dh at least one point of time in the profile if dh_i==1; position_md_i_minus_1=position_md_i-1; combined_1_minus=horzcat(position_md_i_minus_1,position_dh_i); if length(strfind(diff(sort(combined_1_minus)),[0]))>0; fflag=10; end end % when dh_1==2, discard NCMD occurring right before dh at least one point of time in the profile if dh_i==2; position_md_i_plus_1=position_md_i+1; u=union(position_dh_i(1,1:3),position_dh_i(1,4:6)); combined_2_plus=horzcat(position_md_i_plus_1,u); if length(strfind(diff(sort(combined_2_plus)),[0]))>0; fflag=10; end end % when dh_1==2, discard NCMD occurring right after dh at least one point of time in the profile if dh_i==2; position_md_i_minus_1=position_md_i-1; u=union(position_dh_i(1,1:3),position_dh_i(1,4:6)); combined_2_minus=horzcat(position_md_i_minus_1,u); if length(strfind(diff(sort(combined_2_minus)),[0]))>0 fflag=10; end end % when dh_1==3, discard NCMD occurring right before dh at least one point of time in the profile if dh_i==3; position_md_i_plus_1=position_md_i+1; u2=union(position_dh_i(1,1:3),position_dh_i(1,4:6)); uu=union(u2,position_dh_i(1,7:9)); combined_3_plus=horzcat(position_md_i_plus_1,uu); if length(strfind(diff(sort(combined_3_plus)),[0]))>0 fflag=10; end end % when dh_1==3, discard NCMD occurring right after dh at least one point of time in the profile if dh_i==3; position_md_i_minus_1=position_md_i-1; u2=union(position_dh_i(1,1:3),position_dh_i(1,4:6)); uu=union(u2,position_dh_i(1,7:9)); combined_3_minus=horzcat(position_md_i_minus_1,uu); if length(strfind(diff(sort(combined_3_minus)),[0]))>0 fflag=10; end end %% positions of timing clear position_diff_tm_i if dh_i==0; position_diff_tm_i=setdiff(a,position_md_i); end if dh_i==1; position_diff_tm_i=setdiff(a,union(position_md_i,position_dh_i)); end if dh_i==2; position_diff_tm_i=setdiff(a,union(position_md_i,position_dh_i)); end if dh_i==3; position_diff_tm_i=setdiff(a,union(position_md_i,position_dh_i)); end end %% dose time if count > 99 stop1 end if fflag==10 stop2 end dt1=[position_diff_tm_i]*24; dt2=dt1+[diff_tm_i]; dt3=dt2/24; %% dose time dosetime=[0,dt3];