Different "kind" of variable
Afficher commentaires plus anciens
Hi, I would like to ask you how could I create different "kinds" of variable. I am going to create school project about food-macros tracking in Matlab. I need to create three "kinds" of variable - carbohydrates, fats and proteins and I need them to sum by their "kind". How can I do this ?
Thanks, all answers are welcomed !
2 commentaires
Rik
le 3 Mai 2022
If you come up with a specific example of how your data should look and what output you expect it will be easier to give you advice.
Jan Horacek
le 3 Mai 2022
Réponses (1)
typ = ["oats","milk","water"]
mat = [66,12,0;10,8,0;7,8,0]
inp = ["milk","oats"];
qty = [2,0.5];
[~,idx] = ismember(inp,typ);
out = qty*mat(idx,:)
1 commentaire
Jan Horacek
le 3 Mai 2022
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!