필터 지우기
필터 지우기

How to adjust the order of file sorting?

조회 수: 4 (최근 30일)
ahmed
ahmed 2013년 9월 24일
편집: Stephen23 2021년 4월 18일
I am trying to evalute my Lab data, what are represtned into TXT files then plot the conntents of data.
dataDirectory = 'files location ';
allFilesDir = dir(fullfile(dataDirectory , '*.txt'));
allFN = {allFilesDir.name};
result = [];
for n = 1:length(allFN)
measNr(n) = str2double(regexprep(allFN{n},'**.txt',''));
myFN = (fullfile(dataDirectory, allFN{n}));
auxv =try1(myFN);
result(n,:) = mean(auxv.data);
end
This code is workin but into wrong order arrangemnt the TXT files (0,1,11,12,13,14 .....) which give me wrong plot data. I used
plot(measNr,resultMG(1:35,2),'x');
but i read that i can use sort_nat in this way but it did not work for me .
% [~, order] = sort_nat({result});
% result = result(order);
and I got this error messge
:??? Undefined function or method 'sort_nat' for input arguments of type
'cell'.:
  댓글 수: 5
Jan
Jan 2013년 9월 24일
@ahmed: If you are not sure about a command, simply look in its help text:
help sprintf
Stephen23
Stephen23 2015년 5월 27일
편집: Stephen23 2021년 4월 18일
A simple solution is to use my FEX submission natsortfiles
It sorts according to any numeric values in the strings, and also sorts the file extensions separately:
>> 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개)

Walter Roberson
Walter Roberson 2013년 9월 24일

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by