cd frames; this command is showing error.. Kindly help ???
显示 更早的评论
>> part1 Error using cd Cannot CD to frames (Name is nonexistent or not a directory).
Error in part1 (line 4) cd frames;
1 个评论
Beder
2017-2-23
Please provide more of the code and your intentions to be able to help you.
I assume that the variable "frames" does not contain a full path, therefore matlab cannot change directory.
采纳的回答
更多回答(1 个)
Stephen23
2017-2-25
The best solution (fastest, most robust, easiest to debug) is to use fullfile and avoid slow and buggy cd altogether:
sbd = 'C:/somedirectory/mywork'; % pick your directory
for k = 1:15
% generate input filepaths:
fn1 = sprintf('%3.3i.png', k);
fn2 = sprintf('%3.3i.png', k-1);
fp1 = fullfile(sbd,fn1);
fp2 = fullfile(sbd,fn2);
% read input files:
A = imread(fp1, 'png');
A = RGB2GRAY(A);
B = imread(fp2, 'png');
B = RGB2GRAY(B);
% image difference:
C = imabsdiff(A,B);
% save difference in a new file:
fn3 = sprintf('%3.3i-%3.3i.png', k, k-1)
fp3 = fullfile(sbd,fn3);
imwrite(C, fp3, 'png');
end
And DO NOT USE cd. cd is totally unnecessary.
1 个评论
+1: The advice to avoid cd() is valuable. It is only a side-effect, that the original problem is solved, but the code becomes reliable and cannot be confused by a GUI or TIMER callback, which cd's anywhere elese unexpectedly.
Use full path names in every case.
@Priyamkumar Vishwakarma: My answer shows you the problem, Stephen's shows you the best solution. Try Stephen's idea and if it works for you, select it as accepted answer. Thanks.
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!