get values from a table

11 次查看(过去 30 天)
Aj
Aj 2018-2-15
编辑: Niwin Anto 2018-2-22
I have a question:
I have this table:
Lemon Banana Apple
Andy 1 5 8
Roman 6 7 10
Nico 15 22 30
the Variables are 'name' and 'fruit'. When i define name=Andy and fruit=banana, the variable x should be 5. How i can program this and how should i build the table?

采纳的回答

Niwin Anto
Niwin Anto 2018-2-22
编辑:Niwin Anto 2018-2-22
Use the code snippet shown below.
T = table([1;6;15],[5;7;22],[8;10;30],'VariableNames',{'Lemon','Banana','Apple'},...
'RowNames',{'Andy','Roman','Nico'});
name = 'Andy';
fruit = 'Banana';
x = T{name,fruit}
For more about table creation and indexing, refer these links. link1 link2 .

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by