Datetime error when going from r2017a to r2016a

The code is generating an error when using the datetime fuction:
Error using datetime/double (line 1475)
Undefined function 'double' for input arguments of type 'datetime'. To convert from datetimes to numeric, first subtract off
a datetime origin, then convert to numeric using the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions.
This odd because my code works perfectly in r2017a on Windows but I get the error in r2016a on Linux. I have put the code below:
%remove all rows not containing 'OPC.Temperature.BottomTemperature' in
%column 2
temp_string = 'OPC.Temperature.BottomTemperature';
temp_comp = strcmp(data_temp(:,2),temp_string);
temp_comp = ~temp_comp;
data_temp(temp_comp,:) = [];
%remove extra information from columns 3 & 4 from data_temp
data_temp(:,(2:4)) = [];
%convert data_temp cell array to table
data_temp = array2table(data_temp,'VariableNames',{'TimeStamp' 'Temperature'});
%convert timestamp string to datetime
data_temp.TimeStamp = datetime(data_temp.TimeStamp,'InputFormat','yyyy-MM-dd HH:mm:ss.SSS');
%convert temperature string to double precision value
data_temp.Temperature = str2double(data_temp.Temperature);
%remove rows from data_table with temperature below 30C and above 1300C
delete_30 = data_temp.Temperature <30;
data_temp(delete_30,:) = [];
delete_1300 = data_temp.Temperature >1300;
data_temp(delete_1300,:) = [];
%plot temperature vs timestamp
subplot(2,2,1); scatter(data_temp.TimeStamp, data_temp.Temperature); title('Temperature');
The whole code reads a text file using textscan and puts the data into the data_temp variable.
Any thoughts???

 採用された回答

Walter Roberson
Walter Roberson 2017 年 12 月 12 日

0 投票

The ability to use a datetime as an axis on a scatter plot or a plot was not added until R2016b.
For earlier releases you can use datenum() on the datetime, and then be sure to datetick() with an appropriate axis format.

その他の回答 (0 件)

カテゴリ

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

製品

質問済み:

2017 年 12 月 12 日

回答済み:

2017 年 12 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by