필터 지우기
필터 지우기

Indexing of a table.

조회 수: 33 (최근 30일)
Philipp Mueller
Philipp Mueller 2016년 12월 9일
댓글: Peter Perkins 2016년 12월 11일
I have a table called "diagramoptions". This table has 2 columns. With the name Key and Value. For example i want to know the value from number_of_plots. How can i get the number 4? See attachment Picture
My idea: I search the row index of the variable number_of_plots. -> then i try to get the right cell -> (row_index,2) the number 2 is the second column in my table. The return value should be 4.
I tried a lot without any results:
test_value2 = diagramoptions(3,1)% I know it works but it is hardcoded
test_value3 = diagramoptions(:,{'Key'})
thank you

채택된 답변

KSSV
KSSV 2016년 12월 9일
colorval = diagramoptions{3,2}
Your table will be a cell of size 8x2, to pick number of plots you have to give index (3,2) as it's value falls in the index.
  댓글 수: 4
Philipp Mueller
Philipp Mueller 2016년 12월 9일
Great :)
Peter Perkins
Peter Perkins 2016년 12월 11일
Philipp, if your key values are always text, turn them into the row names of the table. Then, to use KSSV's example, you can just do this:
HarryAge = T.Age('Harry')
Even if you don't do that, you may find that
T.Age(strcmp(T.Name,'Harry'))
is simpler than converting the table to a cell array. Hope this helps.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by