Help with Matlab homework quesion
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Can someone help me with this homework? I'm extremely new to MATLAB and have no idea how to do this.
The log.txt file is created from the DICOM film printing software, to record the software's activities.
- Each line corresponds to an event occurring on the system. The data fields are separated by "space", in order:
<date> <time> <event code> <event type> <event details>
- By counting the event lines with the phrase "Printing Done" in the event details, we can calculate the number of printed films.
P/s: I would like to summarize is: ask to count the lines with 'Printing Done', and in 1 day how many lines appear 'Printing Done'. Then output that count data to a txt file.
I have attached 1 .txt file below, because the file is too big, I extracted it.
Please help me.
Thank you.
0 commentaires
Réponses (2)
Image Analyst
le 19 Avr 2022
Try this:
fileContents = fileread('EX.txt');
locations = strfind(fileContents, 'Printing Done')
count = length(locations)
Then call writematrix().
0 commentaires
Eric Delgado
le 19 Sep 2022
Hi Peter, there are a lot of ways to do the same thing. I wrote in Matlab R2021b one of those ways... and I can't avoid commenting what an ugly struct of the log file. :)
Hope it's helpful!
% STEP 1: read table info
opts.VariableNames = ["date", "time", "code", "type"];
opts.VariableTypes = ["datetime", "datetime", "double", "categorical"];
T = readtable('EX.txt', opts);
for ii = 1:height(T)
T.description{ii} = deblank(strjoin(T{ii,5:17}));
end
T(:,5:17) = [];
head(T)
% STEP 2: desirable outputs
% Number of lines with 'Printing Done' info
output1 = sum(contains(T.description, 'Printing Done'))
% Map between the number of lines with 'Printing Done' and days
output2 = table('Size', [0, 2], 'VariableTypes', {'datetime', 'double'}, 'VariableNames', {'date', 'count'});
timestamps = unique(T.date);
for ii = 1:numel(timestamps)
output2(end+1,:) = {timestamps(ii), numel(intersect(find(T.date == timestamps(ii)), find(contains(T.description, 'Printing Done'))))};
end
output2
% STEP3: create files with the outputs (the second is awesome with the Pretty
% Print json!)
writematrix(output1, 'EX_output1.txt')
writematrix(jsonencode(output2, 'PrettyPrint', true), 'EX_output2_json.txt')
0 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown 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!