function tableout = importFaultData(workbookFile,sheetName,startRow,endRow)
%IMPORTFILE Import data from a spreadsheet
%   DATA = importFaultData(FILE) reads data from the first worksheet in the
%   Microsoft Excel spreadsheet file named FILE and returns the data as a
%   table.
%
%   DATA = importFaultData(FILE,SHEET) reads from the specified worksheet.
%
%   DATA = importFaultData(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:
%   faultData = importFaultData('faultData.xlsx','Sheet1',2,464);
%
%   See also XLSREAD.
%
% Copyright 2015 The MathWorks, Inc.

% Auto-generated by MATLAB on 2015/05/20 15:08:48

%% 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 = 464;
end

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

%% Create output variable
I = cellfun(@(x) ischar(x), raw);
raw(I) = {NaN};
data = reshape([raw{:}],size(raw));

%% Create table
tableout = table;

%% Allocate imported array to column variable names
tableout.Fx = data(:,1);
tableout.Fy = data(:,2);
tableout.Fz = data(:,3);
tableout.Tx = data(:,4);
tableout.Ty = data(:,5);
tableout.Tz = data(:,6);
tableout.Fault = cellVectors(:,1);

