issues with sort_nat and natsortfiles; error improper matrix reference

hello, im using the following code :
folderName = 'C:\Users\Shruthi\Desktop\project\A data\SegmentedCharacters';
Imgs = dir(fullfile(folderName, '*.jpg'));
C={Imgs.name};
cx=natsortfiles(C)
q=1;
for blah blah
Img = imread(fullfile(folderName, cx(q).name)); % Read image
q=q+1;
blah blah
end
but it gives me this error
Improper index matrix reference.
Error in Untitled5 (line 142)
Img = imread(fullfile(folderName, cx(q).name)); % Read image
could anyone tell me how i can rectify this? Thank you!

 採用された回答

Stephen23
Stephen23 2017 年 6 月 12 日
編集済み: Stephen23 2021 年 4 月 18 日

1 投票

natsortfiles can now sort the DIR structure directly:
>> S = dir('*.txt');
>> S.name
ans =
'1.txt'
ans =
'10.txt'
ans =
'2.txt'
>> S = natsortfiles(S); % alphanumeric sort by filename
>> S.name
ans =
'1.txt'
ans =
'2.txt'
ans =
'10.txt'

1 件のコメント

shru s
shru s 2017 年 6 月 13 日
編集済み: shru s 2017 年 6 月 13 日
Thank you for writing this beautiful code! It has been very very helpful

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2017 年 6 月 12 日

編集済み:

2021 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by