I have a MATLAB m-file I want to share between computers. I also have a simple batch file I would like to run to launch the MATLAB session and the m-file. The problem is that the folder which has the batch file and m-file must be on the MATLAB search path or MATLAB will error when it tries to run the m-file from the default directory.
I know how to call MATLAB, and how to get it to open the m-file (myfile.m), but how to I tell MATLAB the current directory so that I can first have it cd to that directory. Like how to get the output of chdir to the command?
Here is an easy example: Currently the batch file looks like this:
@echo off
matlab -nosplash -r "myfile"
But I would like to do something like this:
@echo off
matlab -nosplash -r "cd chdir; myfile"
Of course this does not work, as MATLAB tries to cd to a directory chdir which does not exist. But how could I get the results of the DOS command chdir into the argument to MATLAB? That way, wherever the folder is moved on the computer, clicking the batch file will open MATLAB and run the m-file just fine.
Thanks
Aucun commentaire:
Enregistrer un commentaire