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 Kommentare

Rik
Rik am 7 Jul. 2019
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.
Walter Roberson
Walter Roberson am 7 Jul. 2019
datetime() 'convertfrom', 'excel'
is better than x2mdate

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Jul. 2019

1 Stimme

Use readtable().

2 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by