Info
此问题已关闭。 请重新打开它进行编辑或回答。
Error using cd Cannot CD to 7364 (Name is nonexistent or not a directory).
1 次查看(过去 30 天)
显示 更早的评论
I have these two chunks of code. The first one serves to open a still image from each video file and ask me to select a region of interest using a polygon. That step works just fine for all videos (the structure is one large folder with subfolders for each video). Then the next step asks me to measure the arm by clicking two points. That works for the first video, but when the for loop restarts I get an error.
for i = 1:length(nameFolds)
cd(cell2mat(nameFolds(i)));
ToDoList = dir('*.mp4');
ToDo = {ToDoList.name}';
mov = VideoReader(char(ToDo));
imag = read(mov, 60);
imshow(imag);
title(nameFolds(i));
disp('Please draw the boundaries of one of the OPEN arms');
Opens(i,:,:) = roipoly;
disp('Now please draw the boundaries of the other OPEN arm');
Opens(i,:,:) = squeeze(Opens(i,:,:)) + roipoly;
cd(home);
end
if (ArmMeasuring == 1)
for i = 1:length(nameFolds)
cd(cell2mat(nameFolds(i)));
ToDoList = dir('*.mp4');
ToDo = {ToDoList.name}';
mov = VideoReader(char(ToDo));
imag = read(mov, 60);
imshow(imag);
title(nameFolds(i));
disp('Please click two points measuring the length of a single arm');
[x,y] = ginput(2);
ArmLengths(i) = sqrt( (x(1)-x(2))^2 + (y(1)-y(2))^2);
end
end
The error is "Error using cd
Cannot CD to 7364 (Name is nonexistent or not a directory).
Error in EPMCompiler (line 60)
cd(cell2mat(nameFolds(i)));"
I can see that the subfolder entitled 7364 exists and is in the same location as the first subfolder that works fine. Further more, the program is able to find the 7364 folder just fine during the first chunk of code. This is very confusing to me and I'm not sure what's going on.
2 个评论
Stephen23
2020-9-11
"This is very confusing to me and I'm not sure what's going on."
cd is the problem. You can find it in substandard code like this to read files from different directories, whereas the better** approach is to NOT change the directory and simply use absolute/relative filenames:
** better in the sense more robust, more effiicient, easier to debug.
回答(4 个)
John Petersen
2020-9-10
You are changing directories in the first for loop so that by the time you get in to the second for loop you are not starting in the same spot so cd doesn't see the directory.
You need to do something like this:
CurrDir = pwd;
for ...
end
cd (CurrDir)
if (ArmMeasuring == 1)
for ...
end
end
Image Analyst
2020-9-11
Get rid of all calls to cd and get the full file names like this:
topLevelFolder = 'D:\My Videos' % Wherever you want.
filePattern = fullfile(topLevelFolder, '**\*.mp4')
fileNames = dir(filePattern);
for k = 1:length(fileNames)
thisFileName = fullfile(fileNames(k).folder, fileNames(k).name);
fprintf('Processing %s (#%d of %d)...\n', thisFileName, k, length(fileNames));
videoObject = VideoReader(thisFileName);
rgbImage = read(videoObject, 60);
imshow(rgbImage);
title(thisFileName, 'Interpreter', 'none');
promptMessage = sprintf('Please draw the boundaries of one of the OPEN arms');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return;
end
% Opens(k,:,:) = roipoly;
promptMessage = sprintf('Now please draw the boundaries of the other OPEN arm');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return;
end
% Opens(k,:,:) = squeeze(Opens(k,:,:)) + roipoly;
delete(videoObject);
end
0 个评论
Hannah Harder
2020-9-11
1 个评论
Rik
2020-9-11
Which answer are you replying to? Please post this comment there instead of posting it as an answer.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!