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 件のコメント

Rik
Rik 2019 年 7 月 7 日
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 2019 年 7 月 7 日
datetime() 'convertfrom', 'excel'
is better than x2mdate

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 7 日

1 投票

Use readtable().

2 件のコメント

iLikeMatlab
iLikeMatlab 2019 年 7 月 7 日
編集済み: iLikeMatlab 2019 年 7 月 7 日
This means that there is no solution (?) .
Anyway, yes, this works. Thank you Walter.
Walter Roberson
Walter Roberson 2019 年 7 月 7 日
'readvariablenames', false
to prevent the first line being turned into variable names.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by