필터 지우기
필터 지우기

Variable 'Group_Test1' not found.

조회 수: 1 (최근 30일)
sun rise
sun rise 2021년 4월 17일
댓글: sun rise 2021년 5월 28일
clear all
clc
sad = dir('D:\Project\DB1\test\'); % Returns both folders and files
cell_array_of_folder_names = {sad([sad.isdir]).name}; % Select folder names
cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
sorted_cell_array_of_folder_names = sort_nat( cell_array_of_folder_names );
%----------------
[mp1, np] = size(sorted_cell_array_of_folder_names); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
t=1;
for i=3:mp1
%% keep only folders:
P = strfind(sorted_cell_array_of_folder_names(i).name,'.');
if isempty(strfind(sorted_cell_array_of_folder_names(i).name,'.'))
csf1 = csf1 +1; % one sub folder found
SFN = sorted_cell_array_of_folder_names(i).name ;% extract his name
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
%% Processing for each tif file:
for j=1:ms1
tifFileName = tifList(j,:); % extract name of tif file
IM=imread([PF SFN '\' tifFileName]);
%t=1;
%for i=1:csf1
% for j=1:ms1
Group_Test1(t)={i-2};
t=t+1;
end
end
PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName);
end
save('Group_Test','Group_Test1');
%----------------------
  댓글 수: 1
Jan
Jan 2021년 4월 22일
A 3rd thread with the same question is closed. Please stay at one question per problem. Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 4월 17일
편집: Image Analyst 2021년 4월 17일
Obviously you're either not getting into the 'if' or you're not getting into the 'for', and so the Group_Test1 never gets assigned. Here is how to solve it:
  댓글 수: 6
Image Analyst
Image Analyst 2021년 4월 22일
Why are you starting the loop at 3 when you've already removed the . and .. from cell_array_of_folder_names? It should start at 1. And there is no name field of the string in the cell. It's just a regular character array, not a structure.
sad = dir('D:\Project\DB1\test\'); % Returns both folders and files
% sad = dir(pwd); % Returns both folders and files
cell_array_of_folder_names = {sad([sad.isdir]).name}; % Select folder names
% cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
sorted_cell_array_of_folder_names = sort_nat( cell_array_of_folder_names );
% sorted_cell_array_of_folder_names = cell_array_of_folder_names; % if you don't have sort_nat
whos sorted_cell_array_of_folder_names
%----------------
[mp1, np] = size(sorted_cell_array_of_folder_names); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
t=1;
for i=1:mp1
% Skip . and ..
if endsWith(sorted_cell_array_of_folder_names{i}, '.') || endsWith(sorted_cell_array_of_folder_names{i}, '..')
% Skip . and ..
continue; % Skip to bottom of loop.
end
% Keep only folders:
csf1 = csf1 +1; % one sub folder found
SFN = sorted_cell_array_of_folder_names(i).name ;% extract his name
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
% Processing for each tif file:
for j=1:ms1
tifFileName = tifList(j,:); % extract name of tif file
% IM=imread([PF SFN '\' tifFileName]);
%t=1;
%for i=1:csf1
% for j=1:ms1
Group_Test1(t)={i-2};
t=t+1;
end
PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName);
end
% save('Group_Test','Group_Test1');
%----------------------
sun rise
sun rise 2021년 5월 28일
. and .. not removed

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 4월 22일
Before the loop
Group_Test1 = zeros(1, mp1);
In the loop:
Group_Test1(t) = i - 2;
After the loop
Group_Test1 = Group_Test1(1:t-1); % Crop off any unused elements

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by