get values from a table

조회 수: 16 (최근 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에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by