%% Add Style to Specific Cells in Table
% Starting in R2019b, you can style rows, columns, or cells of a table UI component using the uistyle and addStyle functions. Styles are only supported when the table UI component is in a figure created with the uifigure function. App Designer uses this type of figure for creating apps.
% Style cells in a table UI component that contain missing values.  In this case, add a yellow background color style to cells that have NaN values.
% Read tsunami sample data into the workspace as a table array.  Then, create a table UI component to display the data.

tdata = readtable('tsunamis.xlsx');
vars = {'Year','Month','Day','Hour','MaxHeight','Cause','EarthquakeMagnitude'};
tdata = tdata(1:100,vars);

fig = uifigure('Position',[500 500 750 350]);
uit = uitable(fig);
uit.Position = [20 20 710 310];
uit.Data = tdata;
uit.RowName = 'numbered';

%
% Use the ismissing function to get a logical array of the table elements that contain missing values. Find the row and column subscripts for the elements that have NaN values. Finally, create a yellow background color style and add it to the cells with NaN values in the table UI component.

styleIndices = ismissing(tdata);
[row,col] = find(styleIndices);

s = uistyle('BackgroundColor','yellow');
addStyle(uit,s,'cell',[row,col]);

%
% Copyright 2019 The MathWorks, Inc.