Generate the code for an CSS/HTML-based data table from an input numeric, string, or cell array.
The generated HTML code is compatible with any browser and app designer ('HTMLSource' for an HTML element).
With 60 user adjustable parameters, and multiple accepted input formats, the table can be customized in virtually any way.
All parameters are invoked via name-value pairs and validated.
Please read the description at the beginning of the function for details of the arguments and examples.
This function does not support nested tables, i.e., cells within cells, as many parameters need to be matched to the width or height of the table.
Eric Dziekonski (2021). HTMLtable (https://www.mathworks.com/matlabcentral/fileexchange/74823-htmltable), MATLAB Central File Exchange. Retrieved .
Inspired by: Html Table Writer, Display data as an HTML table
Inspired: Model Review Tool
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Matiar,
Change line 875 from:
if iscell(param.Matrix) || (isnumeric(param.Matrix) && numel(param.DataBackgroundColor) == 3 && numel(param.DataFontColor) == 3 && isempty(param.NegativeDataFontColor))
to:
if numel(param.DataBackgroundColor) == 3 && numel(param.DataFontColor) == 3 && isempty(param.NegativeDataFontColor)
The function was shortcutting when it shouldn't be. The function on file exchange has been updated.
Below is a full example of what you described. Note that it is necessary to disable row stripping.
____________________
tempDouble = rand(10,5,2); % 3D numeric matrix of doubles that contains 10 rows, 5 columns, and 2 layers;
tempCell = num2cell(tempDouble); % 3D cell array of doubles;
tempMix = tempCell;
tempMix(:,2:end,:) = cellfun(@string,cellfun(@num2str,tempCell(:,2:end,:),'UniformOutput',false),'UniformOutput',false); % 3D cell array of double/string values
% column 1 of tempMix is a cell array of doubles. All other cells in columns 2-5 are strings.
% create a color matrix that makes column 1 some random color, and columns 2-5 white
colors = [round(rand(10,1,6)*255),ones(10,4,6)*255];
Title = 'Example Table';
RowNames = (1:size(Matrix1,1)).';
ColumnNames = cellfun(@num2str,num2cell(1:size(Matrix1,2)),'UniformOutput',false);
htmlcode = HTMLtable(...
tempMix,...
'PageBackgroundColor',[],...
'Title',Title,...
'TitleFontName','Times New Roman',...
'TitleFontSize',20,...
'TitleFontWeight','bold',...
'TitleFontStyle','normal',...
'TitleFontColor',[],...
'TitleTextAlign','center',...
'TitleBackgroundColor',[],...
'LabelLayer',true,...
'ColumnNames',ColumnNames,...
'ColumnFontName','',...
'ColumnFontSize',9,...
'ColumnPadding',3,...
'ColumnFormat','',...
'ColumnFontWeight','bold',...
'ColumnFontStyle','normal',...
'ColumnFontColor',[],...
'ColumnMinimumWidth',100,...
'ColumnTextAlign','center',...
'ColumnBackgroundColor',[],...
'RowNames',RowNames,...
'RowFontName','Helvetica',...
'RowFontSize',9,...
'RowPadding',3,...
'RowFormat','',...
'RowFontWeight','bold',...
'RowFontStyle','normal',...
'RowFontColor',[],...
'RowTextAlign','center',...
'RowBackgroundColor',[],...
'DataFontName','Helvetica',...
'DataFontSize',9,...
'DataPadding',3,...
'DataFormat','',...
'DataFontWeight','normal',...
'DataFontStyle','normal',...
'DataFontColor',[0,0,0],...
'DataFontColorDimension','row',...
'NegativeDataFontColor',[],...
'DataTextAlign','left',...
'DataBackgroundColor',colors,...
'DataBackgroundColorDimension','table',...
'DataEditable',true,...
'OmitValues',false,...
'Striping',false,...
'StripingColors',[],...
'BorderStyle','solid',...
'BorderWidth',1,...
'BorderColor',[],...
'BorderCollapse','separate',...
'HighlightHover',false,...
'HoverColor',[],...
'HighlightRows',[],...
'HighlightColor',[],...
'ShowOutput',true,...
'RecordRowClick',true,...
'FileName','',...
'OutputToFile',false);
I have a cell array of all strings except one column that is a double and I want to color code that column using DataFontColor or DataBackgroundColor. I can't figure it out any help would be greatly appreciated.
From a high level perspective, it is a highly customizable alternative to Matlab's built-in uitable function.
Matlab's uitable is notoriously slow as each cell acts as its own object. With hundreds or thousands of cells, even scrolling can cause the table to go blank for a second while it renders. This acts as a replacement for uitable and can be set as a uihtml object (app designer compatible). Additionally, it gives many options that uitable does not, such as the ability to customize the header row, add borders, etc. Tables generated via this function can be viewed in a standard web browser as well so that it could be viewed/presented later without needing to reload any data.
I'm a rookie in JS and i'm trying to figure out what is the script for. Is it only to highlight rows ?
Thanks Stephen! I have made the suggested changes; the code is now eval free.
An impressive submission, I will need some time to go through it in detail and try the options.
Note that all of the evil EVAL calls can be replaced by the slightly more robust STR2FUNC, e.g.:
fun = str2func(param.DataFontColor);
colors = fun(nColorValues);