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
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
2022년 5월 3일
답변 (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,:)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!