Extracting Info from the table
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a table for example as below
Team Wins Loss
Ixe 10 5
Tyz 19 1
Fgsd 15 2
I want to access the data from the table but when I do so I get a table back.
For example tb(1,1) i get a table instead of a double. Any help will be appreciated.
댓글 수: 0
답변 (2개)
Rohit Kulkarni
2022년 7월 6일
편집: Rohit Kulkarni
2022년 7월 6일
If you want to access data from multiple variables at once, you can index with curly braces.
Inside the curly braces, you can specify the desired variables by index or variable name.
This will create a numeric array
% for eg
tb_matrix = tb{:, ["Wins" "Loss"]};
%tyz wins
Tyz_wins = tb{2,1}
You can also use dot notation for extraction
tbWins = tb.Wins
%tyz wins
Tyz_wins = tb.Wins(2)
댓글 수: 0
Siraj
2022년 7월 6일
Hii, It is my understanding that your are able to make a table and now you want to access the values from the table. There are certain possible ways of doing it.
- First way is to use the parantheses just as we access the data in the matrices. But keep in mind that whenever you will use parantheses to access the data from a table, the answer will always be a table.
- You can use the dot notation to extract the data. "tb.Wins" will give you a matrix and then you can use the standard way of accessing the data from a matrix, that is using the parantheses.
- You can use the curly braces to extract the data. It works in a similar way as paranthesis indexing but the answer is not a table.
I am attaching the example for all the 3 ways mentioned above.
Hope it helps.
wins = [10, 19, 15]';
loss = [5, 1, 2]';
name = ["Ixe", "Tyz", "Fgsd"]';
arr = [ wins loss ];
tb = array2table(arr,"VariableNames",["Wins","Loss"]);
tb.Team = name;
tb(1,1)
tb{1,1}
tb.Wins(1)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!