Matlab error: Error using cd Cannot CD to Users/JennyOrriss/Dropbox/thesisProject/Batch1/ (Name is nonexistent or not a directory).
古いコメントを表示
Hi i am using matlab (am quite novice at it) and keep getting this error when I run my code.
Error using cd cannot CD to users/Jennyorriss/Dropbox/thesisProject/Batch1 (Name is nonexistent or not a directory)
My matlab script is
% Path for Jenny to use:
pathData = 'Users/JennyOrriss/Dropbox/thesisProject/Batch1/';
Anyone know how I can fix this?
Thanks.
2 件のコメント
Larry Brunson
2019 年 2 月 26 日
Using
cd mypath
tries to append mypath to pwd. Since no such directory exists, you get that error. Instead, use
cd(mypath).
Walter Roberson
2019 年 2 月 26 日
the error message would not have mentioned the path if that had been the problem .
The real problem was quite likely the missing leading /
回答 (2 件)
Image Analyst
2018 年 12 月 15 日
The solution is to not use cd(). Experienced MATLAB programmers don't.
Why not? See the FAQ
Use fullfile() to create filenames, and exist(folder, 'dir') to check that folders exist, and exist(filename, 'file') to check if a file exists (if you need it to exist already).
folder = 'Users/JennyOrriss/Dropbox/thesisProject/Batch1';
if ~exist(folder, 'dir')
message = sprintf('Warning: folder does not exist:\n%s', folder);
uiwait(errordlg(message));
return; % No sense continuing.
end
% If we get to here, the folder exists.
fullFileName = fullfile(folder, 'My Batch File.bat');
% If it needs to exist already, then check for it.
if ~exist(fullFileName, 'file')
message = sprintf('Warning: file does not exist:\n%s', fullFileName);
uiwait(errordlg(message));
return; % No sense continuing.
end
Walter Roberson
2018 年 12 月 16 日
0 投票
you missed the leading / before Users
1 件のコメント
Image Analyst
2018 年 12 月 16 日
Good catch. Sharp eye.
And if you don't have that leading slash, it will look for that folder as a SUBFOLDER of the current folder, which is not where it really is.
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!