Info

此问题已关闭。 请重新打开它进行编辑或回答。

indexing data before and after sort

1 次查看(过去 30 天)
Housam
Housam 2019-5-18
关闭: Housam 2019-5-20
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 个评论
Stephen23
Stephen23 2019-5-19
@Housam: it seems that you are describing your attempted solution, rather than describing what you are actually trying to achieve.
Most likely there are simpler ways to achieve what you need: please clearly described what the aim is, together with example input and output data.
Housam
Housam 2019-5-20
Thank you. yes, Stephen, indeed there was a simpler method to solve the problem. Thankfully, I was able to find a way around it.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by