Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
indexing data before and after sort
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 19 de Mayo de 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.
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!