Accumulating values for different people
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
This is part of a larger project. Finished all that, just need to extract one bit of data which I have trouble doing. I have no start yet as I'm a MATLAB rookie and don't know which command to use for this.
I have a list of 6 people, and they all paid multiple payments, and I'd like to find out how much every person has paid. The data file I have been given looks like the following:
Amount Name
$12,00 Josh
$27,00 Sophie
$18,00 Jeff
$169,00 Josh
And so on for a total of 100 rows. How can I create a table from this that indicates for all 6 people how much they have paid?
Thanks for the help and kind regards,
Matthijs
Antworten (1)
Askic V
am 20 Nov. 2022
Bearbeitet: Askic V
am 20 Nov. 2022
Let's say you have an input data file named 'inputData.txt' with the following structure:
$12,00 Josh
$27,00 Sophie
$18,00 Jeff
$169,00 Josh
Now you need to read this file, preprocess the data and use the function that Walter suggested.
This is how I would do it:
filename = 'inputData.txt'; % define filename
opts = detectImportOptions(filename,'ReadVariableNames',...
false, 'decimal',','); % define read options
T = readtable(filename,opts); % read data into table
T.Var1 = replace(T.Var1, ',', '.');% replace decimal comma with point
T.Var1 = str2double(replace(T.Var1, '$', ''));% get rid of leading $
GC = groupsummary(T, 'Var2','sum') % use groupsummary function
0 Kommentare
Siehe auch
Kategorien
Mehr zu LaTeX 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!