Amrita Pati
Ansys Employee

The syntax for getresult is incorrect. Try using this instead and let me know what hapens:

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");');

Also, since I won't be able to test the whole script as I don't have the simulation file I recommend you to look at the syntax in the file "Coupler_Optimization_Main_Script.m' in the MATALB driven optimization link you shared earlier.

Regards,
Amrita