Different "kind" of variable
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 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
am 3 Mai 2022
Antworten (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 Kommentar
Jan Horacek
am 3 Mai 2022
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!