get values from a table

9 vues (au cours des 30 derniers jours)
Aj
Aj le 15 Fév 2018
Modifié(e) : Niwin Anto le 22 Fév 2018
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?

Réponse acceptée

Niwin Anto
Niwin Anto le 22 Fév 2018
Modifié(e) : Niwin Anto le 22 Fév 2018
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 .

Plus de réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by