Dot indexing is not supported for variables of this type.

3 views (last 30 days)
sad1 = 'D:\Project\DB\train\';
sad = dir(sad1); % Returns both folders and files
% sad = dir(pwd); % Returns both folders and files
cell_array_of_folder_names = setdiff({sad([sad.isdir]).name},{'..','.'}); % Select folder names
% cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
FileList = 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
%Folder = 'D:\Project\DB\train\';
%FileList1 = dir(fullfile(Folder, '**', '*.tif'));
%FileList = sort_nat( FileList1 );
Feature = cell(1, numel(FileList)); % Pre-allocation
for iFile = 1:numel(FileList)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
Img = imread(File);
Img = imresize(Img, [200, 50]);
Feature{iFile} = hog_feature_vector(Img);
end
% Maybe:
Feat1 = cat(1, Feature{:}); % Or cat(2, ...) ?!
save('featurs_T.mat', 'Feat1');
%------------------
sad2 = 'D:\Project\DB\test\';
sad22 = dir(sad); % Returns both folders and files
% sad = dir(pwd); % Returns both folders and files
cell_array_of_folder_names2 = setdiff({sad22([sad22.isdir]).name},{'..','.'}); % Select folder names
% cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
FileList2 = sort_nat( cell_array_of_folder_names2 );
% 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
%Folder2 = 'D:\Project\DB\test\';
%FileList22 = dir(fullfile(Folder2, '**', '*.tif'));
%FileList2 = sort_nat( FileList22 );
Feature2 = cell(1, numel(FileList2)); % Pre-allocation
for iFile2 = 1:numel(FileList2)
File2 = fullfile(FileList2(iFile2).folder, FileList2(iFile2).name);
Img2 = imread(File2);
Img2 = imresize(Img2, [200, 50]);
Feature2{iFile2} = hog_feature_vector(Img2);
end
% Maybe:
Feat2 = cat(1, Feature2{:}); % Or cat(2, ...) ?!
save('featurs_S.mat', 'Feat2');
Dot indexing is not supported for variables of this type.
Error in Untitled4 (line 18)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
  1 Comment
Stephen23
Stephen23 on 23 Jun 2021
Edited: Stephen23 on 23 Jun 2021
Why are you specifically filtering so that cell_array_of_folder_names contains only folder names, but then trying to read those folders as if they were image files?
You should certainly simplify a lot of that code, e.g.:
P = 'D:\Project\DB\train\';
S = dir(fullfile(P,'*.tif'));
S = natsortfiles(S);
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
I = imread(F);
..
S(k).feature = ..
end
Feat1 = cat(1, S.feature);

Sign in to comment.

Accepted Answer

Matt J
Matt J on 22 Jun 2021
Edited: Matt J on 22 Jun 2021
In line 18, you clearly epect FileList to be a structure variable, but it isn't. You should check what it actually is.

More Answers (2)

Walter Roberson
Walter Roberson on 23 Jun 2021
cell_array_of_folder_names2 = setdiff({sad22([sad22.isdir]).name},{'..','.'}); % Select folder names
Those are file names
FileList2 = sort_nat( cell_array_of_folder_names2 );
sort_nat takes in a cell array of character vectors and returns a cell array of character vectors -- that is, FileList2 will be file names (just in sorted order)
File2 = fullfile(FileList2(iFile2).folder, FileList2(iFile2).name);
but there you expect FileList2 to be the output of dir()
cell_array_of_folder_names2 = setdiff({sad22([sad22.isdir]).name},{'..','.'}); % Select folder names
Like the variable name says, those are folder names, so when you then
FileList2 = sort_nat( cell_array_of_folder_names2 );
then what you get out is not a list of files but rather a list of folders
File2 = fullfile(FileList2(iFile2).folder, FileList2(iFile2).name);
Img2 = imread(File2);
but there you are expecting it to refer to image files, not to folders.
If you need to sort by folder name, and then you need to sort by file name, then you will need to sort_nat() the folder names, and then for each folder, dir() the folder to find file names, and sort_nat() the file names.
  1 Comment
sun rise
sun rise on 8 Jul 2021
I need to sort by folder name only, then access the images inside those folders to extract the features

Sign in to comment.


Image Analyst
Image Analyst on 23 Jun 2021
Feature2 = cell(1, numel(FileList2)); % Pre-allocation
for iFile2 = 1:numel(FileList2)
fullFileName = fullfile(sad2, FileList2{iFile2});
Img2 = imread(fullFileName);
Img2 = imresize(Img2, [200, 50]);
title(fullFileName)
drawnow;
Feature2{iFile2} = hog_feature_vector(Img2);
end
  4 Comments
Image Analyst
Image Analyst on 12 Jul 2021
Evidently you have an image called 1. I'm not sure you it found it since it does not have a .tif extension, but that seems to be the problem. imread() might not know how to read in "1" unless it's called "1.tif". Try adding extensions to all your tif images.

Sign in to comment.

Categories

Find more on Shifting and Sorting Matrices 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!