Import tool in r2015a not working like r2014a for excel spreadsheet import as matrix

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 commentaires

I admit I was a little desperate. Thanks and I've modified the heading accordingly.
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.)
Great. I'm currently using the academic license in the university. I don't suppose that's necessarily a student version of Matlab. I would check if I can call Mathworks for support.

Connectez-vous pour commenter.

 Réponse acceptée

I think this might be a bug in reading files with more than a certain number of lines from Excel (5k or 10k, I forget) in the generated code that have a date/time in them. It's bit me a few times but doesn't seem to be in the R2015b prerelease.
As a workaround, use readtable directly.

2 commentaires

Thanks. readtable works well but that means I would have to rewrite my code to work around the new syntax. If all else fails, I would resort to using readtable.
Mathworks support was helpful and the bug was fixed following the instructions in this link. Matlab r2015a import tool bug fixed

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by