Brace indexing is not supported for variables of this type.

3 views (last 30 days)
Hi I need some help. I have created this for loop to extract the images in the different subfolders that are in the given directory in order to process them in another script called Feat_extraction_k. The loop does fine for the first subfolder and the images inside. However, once it reaches the second subfolder the error is displayed for the line with the variable 'Image File' (Brace indexing is not supported for variables of this type) How can I fix this? Thanks.

Accepted Answer

Image Analyst
Image Analyst on 26 Jan 2023
Try this:
filePattern = fullfile(pwd, '*.png');
imds = imageDatastore(filePattern)
allFileNames = imds.Files;
numFiles = numel(imds.Files);
for k = 1 : numel(allFileNames)
% Get this file name.
fullFileName = allFileNames{k};
fprintf('Processing %s\n', fullFileName);
You can set the top level folder in the first line of the code above by replacing pwd with some folder of your own.
  1 Comment
Beatriz on 26 Jan 2023
Thank you so much, this was really helpful! I used this code inside my initial for loop and worked perfectly :)

Sign in to comment.

More Answers (0)


Find more on Structures 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!

Translated by