Reputation: 8818
I am trying to create a uitable in matlab. Consider the following simple example:
f = figure;
data = rand(3);
colnames = {'X-Data', 'Y-Data', 'Z-Data'};
t = uitable(f, 'Data', data, 'ColumnName', colnames, ...
'Position', [20 20 260 100]);
Next, I am trying toset the width and height of the uitable to match the size of the enclosing rectangle:
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
However I get the following error:
>> t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
Attempt to reference field of non-structure array.
When I try to view what t
is, I get:
>> t
t =
2.1030e+03
I don't know what this result means! I am a little confused as this is the first time I am working with uitable
and I am very new to MATLAB too.
Upvotes: 1
Views: 2030
Reputation: 12214
Per the comments, transposing my comment above into an answer.
For the example code to function properly you will need MATlAB R2014b or newer. Per the release notes for MATLAB R2014b, graphics handles are now objects and not doubles, bringing graphics objects in line with the rest of MATLAB's objects. One benefit to this is the user is now able to utilize the dot notation to address and set the properties of their graphics objects. This is a change from older versions where graphics handles were stored as a numeric ID pointing to the relevant graphics object, requiring the user to use get
and set
to access and modify the graphics object properties.
To resolve your issue, you just need to modify the dot notation usage to get or set where appropriate. Or upgrade MATLAB :)
For example,
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
becomes:
tableextent = get(t,'Extent');
oldposition = get(t,'Position');
newposition = [oldposition(1) oldposition(2) tableextent(3) tableextent(4)];
set(t, 'Position', newposition);
Upvotes: 1