Import tool in r2015a not working like r2014a for excel spreadsheet import as matrix
Show older comments
Hi, I'm having a hardtime importing excel spreadsheet with dates into matlab r2015a - something that worked perfectly for me in r2014a. I used the same code I've been using for imports but r2015a is giving me errors. the import function I have is:
if true
function data = importdata(workbookFile, sheetName, range)
%IMPORTFILE1 Import data from a spreadsheet
% DATA = IMPORTFILE1(FILE) reads all numeric data from the first sheet
%%Input handling
% If no sheet is specified, read first sheet
if nargin == 1 || isempty(sheetName)
sheetName = 1;
end
% If no range is specified, read all data
if nargin <= 2 || isempty(range)
range = '';
end
%%Import the data, extracting spreadsheet dates in MATLAB serial date number format (datenum)
[~, ~, raw, dateNums] = xlsread(workbookFile, sheetName, range, '', @convertSpreadsheetDates);
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
%%Replace date strings by MATLAB serial date numbers (datenum)
R = ~cellfun(@isequalwithequalnans,dateNums,raw) & cellfun('isclass',raw,'char'); % Find spreadsheet dates
raw(R) = dateNums(R);
%%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
%%Create output variable
data = reshape([raw{:}],size(raw));
end
In r2015a, I tried this function with a 150x9 spreadsheet with Timestamp in first column and it worked well until I tried to import a 126080x9 spreadsheet with the same timestamp in column 1 and I get this error:
if true
All of the input arguments must be of the same size and shape.
Previous inputs had size 1055 in dimension 1. Input #3 has size 126080
Error in importdata (line 41)
R = ~cellfun(@isequalwithequalnans,dateNums,raw) & cellfun('isclass',raw,'char');
end
I have checked the size of dateNums and raw and they appear not to have the same size. I don't understand why when it worked perfectly on r2014a. Thanks anyone that could help me.
3 Comments
Oluwatobi Williams
on 25 Aug 2015
Walter Roberson
on 25 Aug 2015
When you have questions that need fast technical answers with respect to what might be a bug, then you should take advantage of your Software Maintenance Service to call Mathworks for support.
(Unless, that is, you have a Student Version or Home Version license as those might not include technical support.)
Oluwatobi Williams
on 26 Aug 2015
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!