Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

fibreexport(data)
function varargout = fibreexport(data)
% FIBREEXPORT exports fibre data into an Excel spreadsheet then opens it

% checks the number of arguments
error(nargchk(1, 1, nargin))

% checks the data - it must be numeric, have at least one row, and either
% 2 or 3 columns
if ~isnumeric(data) || size(data, 2) < 2 || size(data, 2) > 3 || size(data, 1) < 1
    % errors
    error('Incorrect data format - there must be at least 1 row, and 2 or 3 columns.')
end

% forms a header
header = {'Time/s', 'Channel 1 Intensity'};

% if there is a third column, extend the header
if size(data, 2) == 3
    % extend it
    header{3} = 'Channel 2 Intensity';
end

% generates a filename
fileName = [fileparts(mfilename('fullpath')), filesep, 'exported_fibre_data_', datestr(now, 'HH_MM_dd_mmm')];

% try-catched for robustness
try
    % export the data
    xlswrite(fileName, [header; num2cell(data)])
    
catch
    % errors
    %error('Did not write Excel file - data possibly too large.')
end

% extends the filename
fileName = [fileName, '.xls'];

% opens the file (if it didn't work, it would've errored already)
if ispc
    % open file
    winopen(fileName)
end

% returns the filename if you left an output argument
if nargout
    % sets it to varargout
    varargout{1} = fileName;
end

Contact us