Column-Width of UI tables

We can modify the column width of uitables in the table definition itself with the following.

Syntax

tab = uitable(uifigure, ‘ColumnWidth’, {<options>}, ‘Data’, <data>)

The ColumnWidth could have following four values:

  1. ‘auto’ – In this case, MATLAB decides the column width automatically, based on factors such as Column name, longest element, etc. This is the default option.
  2. ‘fit’ – This option is only available when a uifigure parent is used. This commands the uitable to fit the columns within the restrictions of the uifigure.
  3. Ratios – This option for uifigure tables as well. This allows to create columns with widths in ration to each other. The base value is ‘1x’. Its twice would be ‘2x’, and so on.
  4. Pixel values – We can pass fixed values for column width in pixel units.

Example 3:

Matlab




% MATLAB Code
uif = uifigure;
  
age = [32 ;23; 15; 17; 19];
names = {'Howard';'Harry'; 'Mark'; 'Nik'; 'Mike'};
gen = {'M'  ;'M' ; 'M'; 'F'; 'M'};
tab = table(age,names,gen);
  
tab = uitable(uif,'ColumnWidth',{29,'fit',39},'Data',tab);


Here, we change the width of all three columns from ‘auto’ to 29px, ‘fit’, 39px respectively. The same can be seen below.

Output:

 

Now, let us see an example where we use the ratio widths.

Example 4:

Matlab




% MATLAB Code
uif = uifigure;
  
age = [32 ;23; 15; 17; 19];
names = {'Howard';'Harry'; 'Mark'; 'Nik'; 'Mike'};
gen = {'M'  ;'M' ; 'M'; 'F'; 'M'};
tab = table(age,names,gen);
  
tab = uitable(uif,'ColumnWidth',{'1x','fit','1x'},'Data',tab);


Output:

 

As it can be seen, the size of ‘fit’ is much less than ‘auto’, which is the case by definition. Another thing to note down is that the width of ‘auto’ changes with window width however, the width of ‘fit’ does not change even on changing window width. 

Control Table UI Component Appearance and Behavior in MATLAB

In this article, we shall discuss how to create UI tables in MATLAB and control their behaviors and appearance by manipulating some basic properties and visuals. UI tables in MATLAB are the graphical form of tabular data. The UI tables can be created using the uitable function.

Syntax

tab = uitable(…parameters…)

The uitable without any parameters generates an empty table. Different parameters could be passed to the same for data modification. We shall not discuss creating UI tables in depth as it is not in this article’s scope. 

Similar Reads

Creating a Basic UI Table

We can create a UI table by passing a prepared data to a uitable component....

UI Tables in a UI Figure

...

Column-Width of UI tables

By default, a new figure is generated by MATLAB for to create a UI table (without any parent figure)....

Fonts in UI tables

...

Colors in UI tables

...