Pull specific data from multiple text files and export it to an excel file.
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to figure out how to pull multiple text files into matlab. Scan each file and pull specific data that I want and then export that data to an excel file.
Specific data I want from each file: Note the files are very large and they have multiple OSIZ components that I want not just 1 row.
1) element # that matches the heading component "OSIZ": "element = some number"
2) flow data: "scfm = 380.0 or whatever the flow is"
3) duct size: "D_duct = some number"
4) orifice size: "D_orif = some number"
What I have so far:
see attached matlab file & example text file.
Thank you fo any help.
4 commentaires
dpb
le 16 Oct 2022
That's not that big in memory footprint; big in terms of hand-processing, yes, but not a memory issues...
Réponses (1)
dpb
le 16 Oct 2022
Modifié(e) : dpb
le 16 Oct 2022
That's not that big in memory footprint; big in terms of hand-processing, yes, but not a memory issues...
data=readlines(websave('testrun.txt','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1158723/testrun.txt'));
ELEMENT= 101122; % set this somehow -- could do a search for all records and present to user???
% engine
matchstr='OSIZ Component data for element =';
isWanted=find(contains(data,matchstr)); % indices to all the OSIZ sections
for i=1:numel(isWanted)
element=str2double(extractBetween(data(isWanted(i)),matchstr,':'));
if element==ELEMENT
flow=str2double(strtrim(extractBetween(data(isWanted(i)+1),'scfm =',':')));
D_duct=str2double(strtrim(extractBetween(data(isWanted(i)+2),'D_duct =','inches')));
D_orif=str2double(strtrim(extractBetween(data(isWanted(i)+3),'D_orif =','inches')));
end
end
What we found is
disp([element])
disp([flow D_duct D_orif])
I didn't show array appending or insertion here; you'll need to increment a counter and insert the values into a preallocated array for each value -- and then wrap the whole thing in a loop iterating over the files in the collection.
Above is the "deadahead" solution using the high-level MATLAB search/matching functions; if this is too slow, can then work on making it more elegant/faster.
2 commentaires
dpb
le 17 Oct 2022
"...; you'll need to increment a counter and insert the values into a preallocated array for each value" is what I said before that I had not shown specifically.
How you structure the rest of the code to call the above and your choice of how you want to hold the values for later use determines the precise use; creating a table for the overall end object might be useful or you can go the other end and just return separate arrays for each...
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!