How to extract some information from a txt file
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Stefania Avvedimento
il 4 Mar 2021
Commentato: Star Strider
il 19 Ott 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 Commenti
Risposta accettata
Star Strider
il 4 Mar 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 Commenti
Star Strider
il 19 Ott 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.
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Import and Export in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!