Info

This question is closed. Reopen it to edit or answer.

indexing data before and after sort

1 view (last 30 days)
Housam
Housam on 18 May 2019
Closed: Housam on 20 May 2019
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 Comments
Stephen23
Stephen23 on 19 May 2019
@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 on 20 May 2019
Thank you. yes, Stephen, indeed there was a simpler method to solve the problem. Thankfully, I was able to find a way around it.

Answers (0)

Community Treasure Hunt

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

Start Hunting!