There is a simple line of command to run OpenSees through Matlab:
! opensees.exe *******.tcl
where it is just needed to put your tcl file name beside of *******.
You just have to :
1- Create a folder, put your M file, tcl file and a copy of opensees.exe in it.
2-write that line of command in your M file. just remember to use the exact name of exe file for the first part and the exact name of tcl file for the second part of this command.
3-Define the path of created folder in "Set Path" part of Matlab.
If you needed to put or remove a text from tcl file using matlab, take a look at "dlmwrite" command in matlab help.