MATLAB: Resorting a list generated by subdirectories

directorieslistsort

Hi. I am trying to read in images from a set of sub directories. I first need to list all directories off my main directories (called newpath). I do this by:
cd(newpath)
p=dir *c*
This generates a list of subdirectoires. Becasue I want to plot the mean of the directories in order, I need to resort the list. At the moment C1.1 is first, then C10.1 etc. I need C1.1, C2.1, C3.1 etc.
Any ideas please?
C1.1 C113.1 C128.1 C142.1 C157.1 C171.1 C186.1 C20.1 C214.1 C229.1 C243.1 C258.1 C272.1 C287.1 C300.1 C43.1 C58.1 C72.1 C87.1
C10.1 C114.1 C129.1 C143.1 C158.1 C172.1 C187.1 C200.1 C215.1 C23.1 C244.1 C259.1 C273.1 C288.1 C301.1 C44.1 C59.1 C73.1 C88.1
C100.1 C115.1 C13.1 C144.1 C159.1 C173.1 C188.1 C201.1 C216.1 C230.1 C245.1 C26.1 C274.1 C289.1 C302.1 C45.1 C6.1 C74.1 C89.1
C101.1 C116.1 C130.1 C145.1 C16.1 C174.1 C189.1 C202.1 C217.1 C231.1 C246.1 C260.1 C275.1 C29.1 C31.1 C46.1 C60.1 C75.1 C9.1

Best Answer

BTW, you don't need to change the directory. Just use
d = dir(fullfile(newpath, '*c*'));