code=strcat('switchtolayout;',...
'groupscope("::model");',...
'set("N",',num2str(N,16),');',...
'set("W_2",',num2str(W2*1e-6,16),');',...
'set("factor",',num2str(factor,16),');',...
'for(0;layoutmode>0; 0) {run;}');
appevalscript(h,code);
%Get the coupled power from T monitor to
%FDTD workspace as variable 'T_avg_FDTD'
code=strcat(['T_1_FDTD=getresult("FDTD","ports","Out1,"T"");' ...
'T_2_FDTD=getresult("FDTD","ports","Out2,"T"");' ...
'T_3_FDTD=getresult("FDTD","ports","Out3,"T"");' ...
'T_4_FDTD=getresult("FDTD","ports","Out4,"T"");']);
appevalscript(h,code);
%Get the average transmission(figure of merit) from FDTD workspace to
%Matlab workspace
T_MatlabFun_1=appgetvar(h,'T_1_FDTD');
T_MatlabFun_2=appgetvar(h,'T_2_FDTD');
T_MatlabFun_3=appgetvar(h,'T_3_FDTD');
T_MatlabFun_4=appgetvar(h,'T_4_FDTD');