Use a single variable name/label with the dot notation, to get access to a table content
Show older comments
Hi, I have a table called "mydata"
>> class(mydata)
ans = 'table'
from which I usually retreive data (stored in its columns) throught the following dot notation command:
mydata.BLUE
mydata.GREEN
mydata.WHITE
...
This time, I would like to use a single "table variable name/label" which contains all the "columns names"
label = {'BLUE','GREEN','WHITE'}
in order to get access to all the data I need. Something like this, that obviously does not work:
for i = 1 : 3
mydata.label(i)
end
Any suggestion?
P.S.: I am not sure if I used the correct matlab terminology to explain my question and for the corresponding title. If both title and question are not clear, I will change them.
1 Comment
Syntaxes given in the documentation for returning the content of one column/variable:
mydata = array2table(randi(9,5,3), 'VariableNames',{'BLUE','GREEN','WHITE'})
mydata.('BLUE') % dot notation
mydata{:,'BLUE'} % curly braces
Accepted Answer
More Answers (1)
POOJA
on 26 Sep 2024
0 votes
You can use dot notation to refer to any individual variable within a table.
x = mytable.Xdata;
y = mytable.Ydata;
The first line of code extracts the variable Xdata from the table mytable and stores the result in a new variable named x. Similarly, the second line of code extracts the variable Ydata into y.
Task
Visualize the letter by plotting the X variable of letter on the horizontal axis and the Y variable on the vertical axis.
HintSee SolutionReset
Submit
Incorrect
Is there a plot?
Does the plot have the correct data?
Hint
Pass letter.X and letter.Y to the plot function.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!