get values from a table

16 Ansichten (letzte 30 Tage)
Aj
Aj am 15 Feb. 2018
Bearbeitet: Niwin Anto am 22 Feb. 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?

Akzeptierte Antwort

Niwin Anto
Niwin Anto am 22 Feb. 2018
Bearbeitet: Niwin Anto am 22 Feb. 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 .

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by