Different "kind" of variable

1 visualización (últimos 30 días)
Jan Horacek
Jan Horacek el 3 de Mayo de 2022
Comentada: Jan Horacek el 3 de Mayo de 2022
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
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
Jan Horacek el 3 de Mayo de 2022
In that program there will be list of food with their macros per 100g/100ml, for example oats (66g carbs, 10g proteins, 7g fats) and milk (12g carbs, 8g proteins, 8g fats) and I need to sum all these macros separately. For example: 50g of oats and 200g of milk means 66/2 + 2*12 CARBS, 10/2 + 2*8 PROTEINS and 7/2 + 2*8 FATS. I hope you understand.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 3 de Mayo de 2022
Editada: Stephen23 el 3 de Mayo de 2022
typ = ["oats","milk","water"]
typ = 1×3 string array
"oats" "milk" "water"
mat = [66,12,0;10,8,0;7,8,0]
mat = 3×3
66 12 0 10 8 0 7 8 0
inp = ["milk","oats"];
qty = [2,0.5];
[~,idx] = ismember(inp,typ);
out = qty*mat(idx,:)
out = 1×3
53 22 0

Categorías

Más información sobre Genomics and Next Generation Sequencing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by