Help with Matlab homework quesion
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Image Analyst
am 19 Apr. 2022
Try this:
fileContents = fileread('EX.txt');
locations = strfind(fileContents, 'Printing Done')
count = length(locations)
Then call writematrix().
0 Kommentare
Eric Delgado
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Startup and Shutdown 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!