Main Content


Remove style from table UI component



removeStyle(uit) removes all styles created with the uistyle function from the specified table UI component. To determine which styles are on uit and available to remove, query the value of uit.StyleConfigurations.


removeStyle(uit,ordernum) specifies which style to remove. Specify a style based on the order in which it was added. The property uit.StyleConfigurations lists styles in the order that they were added.


collapse all

First, add two styles to a table UI component.

fig = uifigure; 
fig.Position = [500 500 520 220];

uit = uitable(fig); 
uit.Data = rand(5); 
uit.Position = [20 30 480 135];

s1 = uistyle('BackgroundColor','red');

s2 = uistyle('BackgroundColor','yellow');

Then, remove both styles to revert the table UI component back to its default appearance.


Add multiple styles to a table UI component, and then remove some of them.

First, create a table UI component and add styles to different parts of it.

fig = uifigure; 
fig.Position = [500 500 720 230]; 
uit = uitable(fig); 
uit.Data = randi([-20,20],7); 
uit.Position = [20 30 680 185]; 
[row,col] = find(uit.Data<0);

s1 = uistyle;
s1.BackgroundColor = 'cyan';
addStyle(uit,s1,'column',[1 3 5]) 

s2 = uistyle;
s2.FontColor = 'red';
s2.FontWeight = 'bold';

s3 = uistyle('BackgroundColor','green');
addStyle(uit,s3,'row',[3 4])


Now, remove the row and column styles. First, query the value of the StyleConfigurations property for the table.

ans=4×3 table
         Target     TargetIndex                Style           
         ______    _____________    ___________________________

    1    column    { 1x3 double}    [1x1]
    2    cell      {20x2 double}    [1x1]
    3    row       { 1x2 double}    [1x1]
    4    column    {[        7]}    [1x1]

The StyleConfigurations property value shows that style order numbers 1 and 4 affect columns, and that the row style was the third style added to the table. Remove the styles by specifying style order numbers 1, 3, and 4.

removeStyle(uit,[1 3 4])

Input Arguments

collapse all

Table component, specified as a Table object created with the uitable function. The Table object must be parented to a figure created with the uifigure function, or one of its child containers.

Style order number, specified as a positive integer or a vector of positive integers. To determine the styles currently applied to the table, and the order in which they were added, query the value of the StyleConfigurations property.

When you remove a style other than the last one that was added, the remaining styles move up in the order to close the gaps. If no style order number is specified, all styles are removed from the table.

Example: removeStyle(uit,2) removes the second style in the list returned by uit.StyleConfigurations.

Example: removeStyle(uit,[1 3 5]) removes the first, third, and fifth styles in the list returned by uit.StyleConfigurations.

Example: removeStyle(uit) removes all styles from the table UI component.

See Also



Introduced in R2019b