Variable 'Group_Test1' not found.
2 views (last 30 days)
Show older comments
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 Comment
Jan
on 22 Apr 2021
You got a solution in your other thread already: https://www.mathworks.com/matlabcentral/answers/809300-dot-indexing-is-not-supported-for-variables-of-this-type
A 3rd thread with the same question is closed. Please stay at one question per problem. Thanks.
Accepted Answer
Image Analyst
on 17 Apr 2021
Edited: Image Analyst
on 17 Apr 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 Comments
Image Analyst
on 22 Apr 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');
%----------------------
More Answers (1)
Image Analyst
on 22 Apr 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
0 Comments
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!