Dot indexing is not supported for variables of this type.

10 views (last 30 days)
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=1: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');
%----------------------
Dot indexing is not supported for variables of this type.
Error in Untitled2 (line 15)
P = strfind(sorted_cell_array_of_folder_names(i).name,'.');
>>

Accepted Answer

Jan
Jan on 21 Apr 2021
Edited: Jan on 21 Apr 2021
Replace:
strfind(sorted_cell_array_of_folder_names(i).name,'.');
% by
strfind(sorted_cell_array_of_folder_names{i},'.');
The name of the variable is cruel: "sorted_cell_array_of_folder_names". But it implies, that the variable is a cell array. So getting the field "name" is not working.
Your code can be simplified:
  • Omit the brute "clear all". It removes all loaded functions from the memory. The reloading from the slow disk wastes time without any benefit.
  • "folder_names" is a nice name, while "cell_array_of_folder_names" impedes reading the code.
  • contains and startsWith are useful. Compare:
cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = [];
with
folder_names(startsWith(folder_names, ".")) = [];
and
P = strfind(sorted_cell_array_of_folder_names(i).name,'.');
if isempty(strfind(sorted_cell_array_of_folder_names(i).name,'.'))
with
P = contains(folder_names{i}, '.');
if ~P
  • This is cruel:
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList);
Creating a char output only to count the lines is very indirect. Nicer:
tifList = dir(fullfile(PF, SFN, '*.tif'));
ms1 = numel(tifList);
  • fullfile cares for the proper file separators.
  4 Comments
Jan
Jan on 22 Apr 2021
Then replace
FolderName = {tifList.folder};
by
FolderName = sort_nat({tifList.folder});

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 22 Apr 2021

Community Treasure Hunt

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

Start Hunting!