You want the output of dir, not the one of sprintf:
file_temp = sprintf('%s\\*.bmp', folder);
filearray = dir(file_temp);
for i = 1:s
[p, f] = fileparts(filearray(i).name);
By the way:
- Please format your code in the forum using the "{} Code" button. It is a good idea to post readable code.
- An easier method to create the file pattern:
file_temp = fullfile(folder, '*.bmp');
- The field .name contains the file name only, so there is no need to split it by fileparts.
p = filearray(i).folder;
f = filearray(i).name;
But you not need p or f at all.
- Use fullfile instead of strcat:
imgname = fullfile(folder, filearray(i).name)