Extracting Info from the table
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Rohit Kulkarni
il 6 Lug 2022
Modificato: Rohit Kulkarni
il 6 Lug 2022
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 Commenti
Siraj
il 6 Lug 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!