How to extract some information from a txt file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Stefania Avvedimento
am 4 Mär. 2021
Kommentiert: Star Strider
am 19 Okt. 2021
Hi all,
I am facing with an issue on how to extract some information from a txt file in a matrix format. Find attached the txt file.
So lets say I want to extract the values of cNH3 over time in a matrix format (let's call matrix 1) and then the values of cNH2CL over time (matrix 2) for nodes ID Node 10, Node 40,Node 265 (not consecutive nodes), how could I do?
Actually I need these information for more than three nodes, lets say for i ID nodes.
Thanks in advance,
Stefania
0 Kommentare
Akzeptierte Antwort
Star Strider
am 4 Mär. 2021
Try this:
fidi = fopen('net3 report.txt');
for k = 1:26
getline = fgetl(fidi);
end
k1 = 1;
while ~feof(fidi)
NN = regexp(fgetl(fidi),'\d*', 'match');
if (isempty(NN)) || (numel(NN) > 1)
break
else
NodeNr(k1,:) = str2double(NN{:});
secread{k1,:} = textscan(fidi,'%s%f%f', 'HeaderLines',4, 'CollectOutput',1);
secread{k1,:}{1} = datetime(secread{k1}{1}, 'InputFormat','mmm:ss','Format','mmm:ss');
k1 = k1 + 1;
end
end
fclose(fidi);
.
10 Kommentare
Star Strider
am 19 Okt. 2021
I am lost.
I am not certain what you want, and I do not understand ‘example results.png’.
The data only imported for ‘Chlorine’ anyway, and for whatever reason readtable did not import the ‘Pipe results’ columns. (Those would require a different appproach to read.)
So in the end, ‘Time_r’, ‘EPANET_r’, and ‘WUDESIM_r’, are all for ‘Chlorine’. The ‘Junc_ID’ then represents each column of the resulting matrices. That code would be essentially the same regardless, because the results would be essentially the same. To get the matrices for the column data to be row vectors instead, simply transpose them.
With respect to 'VariableNamingRule', either substitute that with 'ReadVariableNames',true, or just omit it. Not all versions of readtable support those options.
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!