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!