MATLAB: Error to this line.Functions cannot be indexed using {} or . indexing.

image processing

fn = { dir(fullfile(rootpath, char(subfolders(i)), '*.jpg')).name };

Best Answer

The error message is clear already, isn't it? The core problem is:
fn = {dir(xyz).name};
If dir is a command, you cannot index its output by "." directly. Process it in different steps:
DirList = dir(fullfile(rootpath, subfolders{i}), '*.jpg'));
fn = { DirList.name };
By the way: char(subfolders(i)) wastes time with creating the scalar cell subfolders(i) at first. Using the cell indexing subfolder{i} replies to contained string directly.