Accumulating values for different people
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
Askic V
le 20 Nov 2022
Modifié(e) : Askic V
le 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 commentaires
Voir également
Catégories
En savoir plus sur LaTeX 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!