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

39 views (last 30 days)
fn = { dir(fullfile(rootpath, char(subfolders(i)), '*.jpg')).name };

Accepted Answer

Jan
Jan on 27 Oct 2017
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.

More Answers (0)

Categories

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