Info
此问题已关闭。 请重新打开它进行编辑或回答。
indexing data before and after sort
1 次查看(过去 30 天)
显示 更早的评论
Hello, I need to plot data from a significant number of text files that have the same last digit in their name. My attempt is in the following code. Indexing to the sorted numeric value of the text file name alone does not suffice to get the full path of the text file. Therefore, I need to also find the corresponding non-numeric value of the text file before sorting then join the two parts to get the content of the similarly named text files. I really appreciate the help.
A = { 'C:\MATLAB\folder1_txtfilename_Num_1.txt' ,
'C:\MATLAB\folder1_txtfilename_Num_2.txt' ,
'C:\MATLAB\folder1_txtfilename_Num_3.txt',
'C:\MATLAB\folder2_txtfilename_Num_1.txt',
'C:\MATLAB\folder2_txtfilename_Num_2.txt',
'C:\MATLAB\folder2_txtfilename_Num_3.txt'};
for ii = 1:numel(A)
h1{:,ii} = strsplit(A{:,ii}, 'Num') % seperate the text file name
txt1{:,ii} = h1{1, ii}{1, 1} % get the ~numeric value of the text file name
txt2{:,ii} = h1{1, ii}{1, 2} % get the numeric value of the text file name
[txt2_sorted,I2] = sort(txt2) % get sorted array and its index
end
% find all txt files with same number in txt2_sorted:
for ii = 1:numel(A)
I00 = txt2_sorted'
dd(ii) = cellfun ( @strcmp, I00(1), I00(ii) )
data1 = txt2_sorted(dd)
end
% find the
3 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!