Different "kind" of variable

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 件のコメント

Rik
Rik 2022 年 5 月 3 日
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 2022 年 5 月 3 日
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.

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2022 年 5 月 3 日
編集済み: Stephen23 2022 年 5 月 3 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2022 年 5 月 3 日

コメント済み:

2022 年 5 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by