You'll get better results to your questions if you post in forums more appropriate to your questions (eg. networking instead of Education and Science).
First, what exactly is the error message / error code ?
When you run you script over ssh, the shell's working directory will be "user"'s home directory. I presume foldername is the same as /home/user/foldername (or equivalent). So you are telling the remote shell to run the command myscript.sh by a relative pathname (foldername/myscript.sh). However, your script is assuming that the file matlabfile is either in user's home directory, or that matlab knows where to find it by name.
What directory is your matlabfile located in?
Add the code to the beginning of your script:
This should make things a little more clear.
ls -l matlabfile
Finally, save yourself a little typing. Add
as the first line of your script and then:
Then you can just type foldername/myscript without "sh" preceeding, as well as:
chmod a+x foldername/myscript.sh
ssh firstname.lastname@example.org foldername/myscript.sh