1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mayou
  • 8,498
  • 16
  • 59
  • 98
  • 3
    Do you have MATLAB R2014b? The dot notation for accessing and setting object properties was introduced in R2014b and does not work in earlier versions. See `set` and `get` as an alternative. – sco1 Oct 29 '14 at 16:35
  • @excaza: well, that's a very interesting point and I did not know about it! if you would like to post it just as a small awnswer, I'd give you +1 :) and if someone else would search for something similar, he or she could find the awnser on this page.. – Lucius II. Nov 06 '14 at 12:28

1 Answers1

1

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);
sco1
  • 12,154
  • 5
  • 26
  • 48