MATLAB: How dicomCollection sorts dicom filenames

dicomdicomcollectionimage processingstructure

Hi,
I'm having issues when using dicomCollection to read multi-slice dicom volumes.
I'm basically following steps in this link. But here's my situation:
When loading regular dicom images (the ones I haven't processed), dicomCollection sorts the image slices correctly.
But when I try to load dicom images I created (sub-sampled MR images), it sorts like crazy, with no apparently intuitive ordering.
collection = dicomCollection(MyMRfolder, 'IncludeSubfolders', true);
for idx = 1 : numel(collection.Row)
dicomFilename = collection.Filenames{idx};
end
FYI: there are numbers in my dicom filenames suggesting its order, as image1.dcm, image2.dcm and so on. It happens to the 'untouched' dicom images as well.
How would it sort, if dicom headers such as InstanceNumber were correctly written using dicomwrite?
Thanks

Best Answer

I just used sort to fix the problem
for idx = 1 : numel(collection.Row)
dicomFilename = sort(collection.Filenames{idx});
collection.Filenames{idx} = sort(collection.Filenames{idx});
end
That will correctly sort the files so dicomreadVolume can read it and build the volume correctly.