Matlab sorting numbers oddly

2 次查看(过去 30 天)
Elijah
Elijah 2025-7-3
回答: Paul 2025-7-3
Hello, I am working on a project with data taken at different points in time. I would like to import the data into a 3 dimensional array, with the 1st dimension being intensity, the 2nd wavelength, and the 3rd being time. When I import all the data however, MATLAB seems to be reading it oddly. In windows, all the data is neatly organized according to the timestamp (located in the last 3 digits of the file, corresponding to the seconds elapsed and starting at 0).
Matlab reads it differently however, starting at 0 before jumping to 100-109, 10, 111-119, 11. . . 298, 299, 29, 2, 300-303, 30-39, 3. . . etc.
Is there any way to change the way it reads and sorts files, or maybe batch rename them in matlab? Thank you

回答(2 个)

Walter Roberson
Walter Roberson 2025-7-3
编辑:Walter Roberson 2025-7-3
The filename order that MATLAB is using is whatever is returned by the operating system. In turn Windows relies on whatever is returned by the NTFS filesystem driver. The file sort order of NTFS is not documented, but experimentally it appears to sort based on byte order of filename representation. Byte order of filename representation apparently gets locked in according to the LANGUAGE environment setting of the person who created the NTFS filesystem -- so two different NTFS filesystem might have different sort orders.
The sorting appears to be by name moving from left to right -- and '_' sorts after the digits, so '1_' sorts after '19'

Paul
Paul 2025-7-3
Hi Elijah,
Would be helpful if you showed the code for reading the files.
If I'm understanding correctly, maybe you could use dir to get all of the file names, process the name field of the output of dir to get the names sorted by time stamp, and then read the files in sorted order?

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by