there is a webinar on SPM and XPM, I think I sent the link to you where you have to register to get the webinar material. after you see it, feel free to ask any question to discuss.
Regarding the matlab cosimulation with OptiSystem, there is also another webinar explaining that.
I have created a simple example to you (attached)
, you can try it after you see the webinar. please put the .osd and the matlab file in the sae directory and try it.
best of luck and let me know if you have any question to discuss