function tableout = importtickers(workbookFile,sheetName,startRow,endRow)
%IMPORTFILE Import data from a spreadsheet
%   DATA = IMPORTFILE(FILE) reads data from the first worksheet in the
%   Microsoft Excel spreadsheet file named FILE and returns the data as a
%   table.
%
%   DATA = IMPORTFILE(FILE,SHEET) reads from the specified worksheet.
%
%   DATA = 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.
%
%	Non-numeric cells are replaced with: NaN
%
% Example:
%   tickersSP100 = importfile('tickersSP100.xlsx','Sheet1',2,103);
%
%   See also XLSREAD.

% Auto-generated by MATLAB on 2017/09/23 20:31:30

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

%% Import the data, extracting spreadsheet dates in Excel serial date format
[~, ~, raw1, dates1] = xlsread(workbookFile, sheetName, sprintf('A%d:A%d',startRow(1),endRow(1)),'' , @convertSpreadsheetExcelDates);
[~, ~, raw2, dates2] = xlsread(workbookFile, sheetName, sprintf('D%d:E%d',startRow(1),endRow(1)),'' , @convertSpreadsheetExcelDates);
raw = [raw1,raw2];
dates = [dates1,dates2];
for block=2:length(startRow)
    [~, ~, tmpRawBlock1, tmpDateNumBlock1] = xlsread(workbookFile, sheetName, sprintf('A%d:A%d',startRow(block),endRow(block)),'' , @convertSpreadsheetExcelDates);
    [~, ~, tmpRawBlock2, tmpDateNumBlock2] = xlsread(workbookFile, sheetName, sprintf('D%d:E%d',startRow(block),endRow(block)),'' , @convertSpreadsheetExcelDates);
    raw = [raw;tmpRawBlock1,tmpRawBlock2]; %#ok<AGROW>
    dates = [dates;tmpDateNumBlock1,tmpDateNumBlock2]; %#ok<AGROW>
end
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
stringVectors = string(raw(:,1));
stringVectors(ismissing(stringVectors)) = '';
raw = raw(:,3);
dates = dates(:,2);

%% Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),dates); % Find non-numeric cells
dates(R) = {NaN}; % Replace non-numeric Excel dates with NaN

%% 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.Symbol = stringVectors(:,1);
dates(~cellfun(@(x) isnumeric(x) || islogical(x), dates)) = {NaN};
tableout.Datefirstadded = datetime([dates{:,1}].', 'ConvertFrom', 'Excel');
tableout.CIK = data(:,1);

% For code requiring serial dates (datenum) instead of datetime, uncomment
% the following line(s) below to return the imported dates as datenum(s).

% tableout.Datefirstadded=datenum(tableout.Datefirstadded);

