>> part1 Error using cd Cannot CD to frames (Name is nonexistent or not a directory).
Error in part1 (line 4) cd frames;

1 件のコメント

Beder
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.

サインインしてコメントする。

 採用された回答

Jan
Jan 2017 年 2 月 23 日

0 投票

Does the variable frames contain a string with the name of a folder or do you want to change into the current subfolder named 'frames'?
frames = 'C:\Temp\'
cd('C:\');
cd(frames) % Change to C:\Temp\
cd('frames') % Change to C:\frames
cd frames % Change to C:\frames

2 件のコメント

Priyamkumar Vishwakarma
Priyamkumar Vishwakarma 2017 年 2 月 25 日
cd frames;
for i = 1:15, filename1 = sprintf('%3.3i.png', i); filename2 = sprintf('%3.3i.png', i-1); A = imread(filename1, 'png'); A = RGB2GRAY(A);
B = imread(filename2, 'png');
B = RGB2GRAY(B);
C = imabsdiff(A,B);
imwrite(C, sprintf('%3.3i-%3.3i.png', i, i-1), 'png');
end
cd ..
disp('Done.');
The above is my code .....
Still the error persist. Please Help...
>> part1 Error using cd Cannot CD to frames (Name is nonexistent or not a directory).
Error in part1 (line 10) cd frames;
The above is the error.. Kindly help to resolve
Jan
Jan 2017 年 2 月 25 日
編集済み: Jan 2017 年 2 月 25 日
It is still not clear, if you want to change to the folder ".\frames\" or if "frames" is a variable containing the folder name. What do you expect "cd frames;" to do?

サインインしてコメントする。

その他の回答 (1 件)

Stephen23
Stephen23 2017 年 2 月 25 日

1 投票

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 件のコメント

Jan
Jan 2017 年 2 月 25 日
編集済み: Jan 2017 年 2 月 27 日
+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 についてさらに検索

タグ

質問済み:

2017 年 2 月 23 日

編集済み:

Jan
2017 年 2 月 27 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by