How can I run scripts with the same name, that are contained in different folders?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a folder structure like the following:
C:\Work\Version1\myFile.m
C:\Work\Version2\myFile.m
If my working directory is C:\Work\, how can I specify which version of myFile.m should be executed?
Respuesta aceptada
MathWorks Support Team
el 27 de Jun. de 2009
This can be done using the RUN function availabe in MATLAB by specifying the folder and filename to be executed in the RUN command. for example,
run('C:\Work\Version1\Myfile'); % to execute the file in 1st folder
run('C:\Work\Version2\Myfile'); % to execute the file in 2nd folder
Another possibility is to use anonymous functions, as follows:
anon1 = @() run('C:\Work\Version1\Myfile');
anon2 = @() run('C:\Work\Version2\Myfile');
anon1() % Version 1 executed
anon2() % Version 2 executed
A third method to do the same thing is shown below:
actualPath = 'C:\Work\Version1\'
run([actualPath 'myFile']); % With or without .m extension.
actualPath = 'C:\Work\Version2\'
run([actualPath 'myFile']);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Files and Folders en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!