I am getting error in the following code

2 ビュー (過去 30 日間)
Anu G
Anu G 2019 年 9 月 24 日
コメント済み: Anu G 2019 年 9 月 26 日
Code:
function resize()
prompt = 'What dataset u want to choose? - (enter corel10k OR corel5k OR wang) ';
str = input(prompt,'s');
FileList = dir(fullfile(str,'*.jpg'));
F = natsortfiles({FileList.name});
Result = cell(1, numel(F));
for iFile = 1:numel(F)
File = fullfile(str, F(iFile));
Img = imread(cell2mat(File));
J = imresize(Img, [256 256]);
filename2=sprintf('samesize/myimage%02d.jpg',iFile);
imwrite(J,filename2);
end
end
Error:
Cell contents indices must be greater than 0
Error in natsortfiles (line 135)
vec{numel(len)} = [];
Error in resize (line 5)
F = natsortfiles({FileList.name});

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 24 日
Suppose that there are no *.jpg files in the subdirectory of the current directory that the user names in response to input(). Then the dir() would return empty and {FileList.name} would be an empty cell, and natsortfiles does not expect that.
  1 件のコメント
Anu G
Anu G 2019 年 9 月 26 日
Thank you

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by