Matlab sorting numbers oddly

조회 수: 6 (최근 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'
  댓글 수: 1
Elijah
Elijah 2025년 7월 3일
this worked! thank you!

댓글을 달려면 로그인하십시오.


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