Compatibility Mac vs Windows

Hi there,
I realized that there is a compatibility issue with the xlsread function concerning the operating system, This compatibility issue creates reporducability problems when it comes to testing the code. More specifically:
[data, txt, raw] = xlsread(filename,sheet,xlRange);
When it comes to running this code on a Mac (R2018b), what I get is the full range data including the the first column which has to do with dates under the variable "data" , all the char values under the variable "txt" (at my example an 0x0 empty cell array) and a cell array again with all the data within the xlRange under the variable "raw", with the dates in their Excel-numeric version.
At this point let me specify the fact the first column of my data are dates with the format dd/mm/yyyy and the rest just numerical values no characters or names etc, etc..
When I import the above data (time series) in MATLAB i just have to run the :
dates = x2mdate(data(:,1));
function in order to get the correct numerical dates under the MATLAB framework, and everything just works fine especially when it comes to plotting the time series when I use the:
dates = datestr(dates);
t = datetime(dates);
functions .
Well, I grab this piece of code and throw it into a Windows installed MATLAB (R2018b). Things are a bit different, and annoying.... :
  • data : contains only the columns 2:8 without the first column of dates compared to the data variable on a mac where I also get the first column with numeric dates under the Excel format.
  • txt : is a full cell array with the first column containing the dates according to the Excel's sheet format as char
  • raw : is a full cell array containing everything, however, the first column of dates are chars under the Excel's sheets format.
This means that I cannot reproduce the code in different operating systems. Can anyone please specify a solution or an explanation to this? Do I really have to insert if statements for the user to choose the operting system and follow the corresponding code to run the program? ....annoying.
Thank you all in advance.

2 Comments

Not really a solution to your problem, but you can use ispc isunix and ismac functions to determine the host OS. Note that the isunix function returns true for both Linux and Mac.
datetime() 'convertfrom', 'excel'
is better than x2mdate

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 7 Jul 2019
Use readtable().

2 Comments

iLikeMatlab
iLikeMatlab on 7 Jul 2019
Edited: iLikeMatlab on 7 Jul 2019
This means that there is no solution (?) .
Anyway, yes, this works. Thank you Walter.
'readvariablenames', false
to prevent the first line being turned into variable names.

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!