% This script runs a simple example of latexTable.m
%clc; 
clear input;

%% Example 1: using an array as data input
%fprintf('Output array into latex\n\n');

% row labels (set empty string for multiline rows):
%input.tableRowLabels = cell(mat2str(rrange));
input.tableRowLabels = cell(size(rrange));
%%%%????how to vectorize the following?????
for ii=1:length(rrange),
     input.tableRowLabels{ii} = ['r=' num2str(rrange(ii))];
end
%input.tableRowLabels = num2cell(num2str(rrange'));

% numeric values you want to tabulate:
% this field has to be an array or a MATLAB table
% in this example we use an array
  % also in runmaxrank.m
input.tableData =...
  [ranklengths' minfinaliters' maxfinaliters' meanfinaliters' maxcos' maxranks']; 

% Optional fields (if not set default values will be used):

% column labels:
input.tableCloumnHeaders = {'rank steps','min-iters','max-iters','mean-iters','max-cos','max rank'};

% Formatting-string to set the precision of the table values:
% For using a single format for all values in input.tableData use
% just one format string in the cell array like {myFormatString}
% e.g. input.tableDataRowFormat = {'%.3f'};
% For using different formats in different rows use a cell array like
% {myFormatString1,numberOfRows1,myFormatString2,numberOfRows2, ... }
% where myFormatString_ are formatting-strings and numberOfRows_ are the 
% number of table rows that the preceding formatting-string applies.
% Make sure the sum of numberOfRows_ matches the number of rows in input.tableData!
% For further information about formatting strings see 
% http://www.mathworks.de/de/help/matlab/matlab_prog/formatting-strings.html
% In this example we want to use a different format for the last row:
%input.tableDataRowFormat = {'%.3f',3,'%.2f',1};
%input.tableDataRowFormat = cellstr(repmat('%5i',size(rrange,1),1));  %??? works?
MyFormatString=  '%i';  % only single format per row seems to work???
%MyFormatString=  ['%.2f';'%.4g'];  % how???? nothing seems to work??
input.tableDataRowFormat = {MyFormatString,length(rrange)};

% Define how NaN values in input.tableData should be printed in the LaTex table:
input.tableDataNanString = 'NaN';

% Column alignment ('l'=left-justified, 'c'=centered,'r'=right-justified):
input.tableColumnAlignment = 'c';

% Switch table borders on/off:
input.tableBorders = 1; 

% LaTex table caption:
input.tableCaption = ['Using DR algorithm; with [m n k mn toler iterlimit]= [' num2str([m n k m*n toler iterlimit]) ']; max/min/mean iter and number rank steps for finding max-rank of P']; 
% LaTex table label:
input.tableLabel = 'DRmaxitermaxrankP';

% Switch to generate a complete LaTex document or just a table:
input.makeCompleteLatexDocument = 1;

% Now call the function to generate LaTex code:
latex = latexTable(input);


%%
%%%% Example 2: using MATLAB table datatype as data input
%%
%%% Please note: since the table datatype was introduced in MATLAB version r2013b,
%%% you cannot use this feature in older versions of MATLAB!
%%% Check MATLAB version:
%%DateNumberThisVersion = datenum(version('-date'),'mmmm dd, yyyy');
%%if DateNumberThisVersion < 735459 % MATLAB r2013b release day was datenumber 735459
%%    fprintf('\n\nCannot run example 2: This MATLAB version does not support datatype ''table''!\n');
%%    break;
%%end
%%
%%fprintf('\n\nExample 2: using MATLAB table datatype as data input\n\n');
%%
%%% Set up a MATLAB table (similar to example used in MATLAB docs):
%%% Please note that the resulting LaTex table is row-based, not
%%% column-based. So the LaTex table is a 'transposed' copy of the MATLAB table.
%%LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
%%Age = [38;43;38;40;49];
%%Height = [71;69;64;67;64];
%%Weight = [176;163;131;133;119];
%%T = table(Age,Height,Weight,'RowNames',LastName);
%%
%%% Now use this table as input in our input struct:
%%input.tableData = T;
%%
%%% Set the row format of the data values (in this example we want to use
%%% integers only):
%%input.tableDataRowFormat = {'%i'};
%%
%%% Column alignment ('l'=left-justified, 'c'=centered,'r'=right-justified):
%%input.tableColumnAlignment = 'c';
%%
%%% Switch table borders on/off:
%%input.tableBorders = 1; 
%%
%%% Switch to generate a complete LaTex document or just a table:
%%input.makeCompleteLatexDocument = 1;
%%
%%% Now call the function to generate LaTex code:
%%latex = latexTable(input);
