Set variable equal to folder in path
8 次查看(过去 30 天)
显示 更早的评论
I am running a script in multiple directories. They are organized like this:
MainDir/SubDir1/SubDir2/AnalysisDir1
I want to store the string "SubDir1" as a variable, which I will later insert into the name of the output files.
Here's how I accomplish this in cygwin:
cd ./../../
SubDir1="${PWD##*/}"
cd ./SubDir2/AnalysisDir
Any help would be much appreciated.
0 个评论
回答(2 个)
Steven Lord
2020-5-4
Assuming you start off in MainDir:
S = 'SubDir1';
A = fullfile(pwd, S, 'SubDir2', 'AnalysisDir1');
fprintf('Changing directory to %s.\n', A)
cd(A)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!