why can't I use uitable to display a table on a figure?

28 views (last 30 days)
I want to show the parameters of a matlab system object within a figure.
I use get to return the parameters as a struct
I use struct2table to convert it to a table
I use uitable to display the table and get
Warning: This implementation of uitable is no longer supported and will be removed in a future release.
See the documentation for correct uitable usage:
help uitable and doc uitable
Warning: This implementation of uitable is no longer supported and will be removed in a future release.
> In uitable_deprecated
So now I understand that it's deprecated. I'm directed to the help documentation but the documentation does not to help
So I use cell2mat to get an array of values
I write a few lines of matlab to get an array of strings
I use table to create a table from the two arrays
I use uitable on this table and I get
Error using uitable
Functionality not supported with figures created with the figure function.
Error in uitable (line 54)
thandle = builtin('uitable', varargin{:});
I give up
  2 Comments
dale finney
dale finney on 29 Apr 2024
I point out that the error message says 'not supported with figures created with the figure function'
The help documentations says
'uit = uitable creates a table UI component in the current figure and returns the Table UI component object. If there is no figure available, MATLAB® calls the figure function to create one.'
what am I missing?
Voss
Voss on 29 Apr 2024
You describe trying a couple of different things, but each one ultimately tries to use a table array (i.e., a table variable, such as those produced by the table function or the struct2table function) as the uitable's Data, which is not supported for uitables in figures created with the figure function. See my answer for examples of using other classes of variables as uitable Data in figures created with the figure function.

Sign in to comment.

Accepted Answer

Voss
Voss on 29 Apr 2024
Edited: Voss on 29 Apr 2024
A uitable's Data cannot be a table variable if the uitable is in a figure created with the figure function. See the description under Data here:
  • Table array (uifigure-based apps only) — Displays any combination of data types that table arrays support, such as datetime, duration, and categorical.
  • Numeric array — Displays numeric values such as double or single.
  • Logical array — Displays check boxes. true values correspond to selected boxes, whereas false values display cleared boxes.
  • Cell array — Displays any combination of numeric, logical, or character array values.
  • String array — Displays characters and text.
  • Cell array of character vectors — Displays characters and text.
Every class listed there besides "table array" is (supposedly) supported in uitables in figures created by the figure function, so you'll have to choose one of those. (Actually, I find that using a string array gives the same error that using a table array does.)
Examples:
data = rand(4,3); % numeric array
figure('Position',[10 10 300 100])
t = uitable('Position',[1 1 300 100],'Data',data);
data = [false, false; true, false; true true]; % logical array
figure('Position',[10 10 300 100])
t = uitable('Position',[1 1 300 100],'Data',data);
data = {1.2,true,'c';3.4,false,'f'}; % cell array
figure('Position',[10 10 300 100])
t = uitable('Position',[1 1 300 100],'Data',data);
data = {'a','bb','ccc';'dddd','eeeee','ffffff'}; % cell array of character vectors
figure('Position',[10 10 300 100])
t = uitable('Position',[1 1 300 100],'Data',data);
try
data = ["a","b","c";"d","e","f"]; % string array (doesn't work)
figure('Position',[10 10 300 100])
t = uitable('Position',[1 1 300 100],'Data',data);
catch e
disp(e.message);
end
Functionality not supported with figures created with the figure function.
try
data = table([1;2;3],["a";"b";"c"],[true;false;true]); % table array (doesn't work)
figure('Position',[10 10 300 100])
t = uitable('Position',[1 1 300 100],'Data',data);
catch e
disp(e.message);
end
Functionality not supported with figures created with the figure function.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!