Accessing data in matrix entries of tables

3 Ansichten (letzte 30 Tage)
Luca Bernini
Luca Bernini am 8 Jun. 2021
Kommentiert: Luca Bernini am 8 Jun. 2021
Dear all,
I am having trouble to access matrix data in tables. To explain better my problem I'm posting a MWE.
x = {1 "abc" [1 2;2 1];2 "def" [3 4;4 3];3 "ghi" [3 4;4 3]};
T = cell2table(x,'VariableNames',{'id','names','matdata'});
I am able to access data in table T as rows and variables. For example I can access the 1st row of "id" variable as:
T{1,'id'}
I am not able to access the table first row of variable "matdata" as a double matrix directly (the operation below returns a cell):
T{1,'matdata'}
So, my question is if there is a direct way to access the matrix [1 2;2 1] as a double, and if possible to access even directly to its rows or columns with a sigle line of code, so without the need of an auxiliary variable. By now I found this solution but it needs an auxiliary variable:
aux = table2array(T{1,'matdata'});
aux(1,:)
Instead I can do this directly with the "x" cell:
x{1,end}(1,:)
Thanks to all in advance for your advice and suggestions!

Akzeptierte Antwort

Duncan Po
Duncan Po am 8 Jun. 2021
You can use multiple sets of curly braces {} to index into cells, and then use parentheses to index into the resulting arrays, like this:
>> T{1,'matdata'}{1}(1,:)
ans =
1 2

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by