Variable 'Group_Test1' not found.

11 vues (au cours des 30 derniers jours)
sun rise
sun rise le 17 Avr 2021
Commenté : sun rise le 28 Mai 2021
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 commentaire
Jan
Jan le 22 Avr 2021
A 3rd thread with the same question is closed. Please stay at one question per problem. Thanks.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 17 Avr 2021
Modifié(e) : Image Analyst le 17 Avr 2021
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 commentaires
Image Analyst
Image Analyst le 22 Avr 2021
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 le 28 Mai 2021
. and .. not removed

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 22 Avr 2021
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

Community Treasure Hunt

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

Start Hunting!

Translated by