Microscopy Image Browser 2.91
MIB
Loading...
Searching...
No Matches
mibSaveTableToHeaderCSV.m File Reference

Save MATLAB Table (T) to CSV file (fn) with a header standard MATLAB writetable function does not support generation of headers, this function allows to produce CSV file with header generated from table Properties. More...

Functions

function  mibSaveTableToHeaderCSV (fn, T)
 Save MATLAB Table (T) to CSV file (fn) with a header standard MATLAB writetable function does not support generation of headers, this function allows to produce CSV file with header generated from table Properties.
 

Detailed Description

Save MATLAB Table (T) to CSV file (fn) with a header standard MATLAB writetable function does not support generation of headers, this function allows to produce CSV file with header generated from table Properties.

Function Documentation

◆ mibSaveTableToHeaderCSV()

function mibSaveTableToHeaderCSV ( fn,
T )

Save MATLAB Table (T) to CSV file (fn) with a header standard MATLAB writetable function does not support generation of headers, this function allows to produce CSV file with header generated from table Properties.

Parameters
fnfull path to the destination filename
TMATLAB table, the the following examples for details of usage
Required fields of T:

Examples:

generate data for the table
conditionNames = {'WT', 'Treatment'}; % define conditions for data
dataMatrix = {};
dataMatrix{1} = [1:10; rand([1, 10])]'; % populate table with WT data
dataMatrix{2} = [1:5; rand([1, 5])]'; % populate table with Treatment data
% for table number of rows should be the same for all conditions
maxLength = max(cellfun(@length, dataMatrix)); % determine the maximum length of the vectors in the cell array
dataMatrix = cellfun(@(v) [v; NaN(maxLength-length(v), size(v,2))], dataMatrix, 'UniformOutput', false); % pad each vector with NaNs to make them the same length
resultsTable = table(dataMatrix{:}, 'VariableNames', conditionNames); % init the table
resultsTable = addprop(resultsTable,{'XLabel','YLabel'}, {'variable','variable'}); % [optional] add properties for X and Y labels
resultsTable.Properties.Description = 'Desctiption of the table'; % [optional] add description
resultsTable.Properties.RowNames = cellfun(@num2str,num2cell(1:10),'UniformOutput',false); % [optional] add row names
for condId=1:numel(conditionNames) % [optional] add additional info
resultsTable.Properties.VariableDescriptions{condId} = sprintf('Condition %d description', condId);
resultsTable.Properties.VariableUnits{condId} = 'um'; % units
resultsTable.Properties.CustomProperties.XLabel{condId} = 'x label'; % x label for data
resultsTable.Properties.CustomProperties.YLabel{condId} = 'y label'; % y label for data
end
mibSaveTableToHeaderCSV('d:\myfiles\output.csv', resultsTable); % save table to CSV
A MatLab cell array or matrix.
#define max(a, b)
Definition imgaussian.c:8
function mibSaveTableToHeaderCSV(fn, T)
Save MATLAB Table (T) to CSV file (fn) with a header standard MATLAB writetable function does not sup...
Definition mibSaveTableToHeaderCSV.m:17

see more examples in MCcalc2 plugin Updates