Code covered by the BSD License  

Highlights from
MATLAB Tools for Scientist

image thumbnail

MATLAB Tools for Scientist

by

 

Files from the webinar: MATLAB Tools for Scientists- Introduction to Data Analysis and Visualization

importfile(workbookFile,sheetName,startRow,endRow)
function [ID,Dose,Response,Tmt,Age,Gender] = importfile(workbookFile,sheetName,startRow,endRow)
%IMPORTFILE Import data from a spreadsheet
%   [ID,Dose,Response,Tmt,Age,Gender] = IMPORTFILE(FILE) reads data from
%   the first worksheet in the Microsoft Excel spreadsheet file named FILE
%   and returns the data as column vectors.
%
%   [ID,Dose,Response,Tmt,Age,Gender] = IMPORTFILE(FILE,SHEET) reads from
%   the specified worksheet.
%
%   [ID,Dose,Response,Tmt,Age,Gender] =
%   IMPORTFILE(FILE,SHEET,STARTROW,ENDROW) reads from the specified
%   worksheet for the specified row interval(s). Specify STARTROW and
%   ENDROW as a pair of scalars or vectors of matching size for
%   dis-contiguous row intervals. To read to the end of the file specify an
%   ENDROW of inf.%
% Example:
%   [ID,Dose,Response,Tmt,Age,Gender] =
%   importfile('Data.xlsx','Sheet1',2,261);
%
%   See also XLSREAD.

% Auto-generated by MATLAB on 2012/11/13 15:55:20
% Copyright 2011 - 2012 MathWorks, Inc.
%% Input handling

% If no sheet is specified, read first sheet
if nargin == 1 || isempty(sheetName)
    sheetName = 1;
end

% If row start and end points are not specified, define defaults
if nargin <= 3
    startRow = 2;
    endRow = 261;
end

%% Import the data
[~, ~, raw] = xlsread(workbookFile, sheetName, sprintf('A%d:F%d',startRow(1),endRow(1)));
for block=2:length(startRow)
    [~, ~, tmpRawBlock] = xlsread(workbookFile, sheetName, sprintf('A%d:F%d',startRow(block),endRow(block)));
    raw = [raw;tmpRawBlock]; %#ok<AGROW>
end
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
cellVectors = raw(:,[4,5,6]);
raw = raw(:,[1,2,3]);

%% Create output variable
data = reshape([raw{:}],size(raw));

%% Allocate imported array to column variable names
ID = data(:,1);
Dose = data(:,2);
Response = data(:,3);
Tmt = cellVectors(:,1);
Age = cellVectors(:,2);
Gender = cellVectors(:,3);

Contact us