Different "kind" of variable
Mostrar comentarios más antiguos
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 comentarios
Rik
el 3 de Mayo de 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
el 3 de Mayo de 2022
Respuestas (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 comentario
Jan Horacek
el 3 de Mayo de 2022
Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!