How can I run scripts with the same name, that are contained in different folders?
5 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
MathWorks Support Team
2009-6-27
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!