I have to construct a semi log plot with logarithmic y axis. My x axis type is datetime. In general, to accomplish this, one can use semilogy command. Below written sample code gives a gist of what I would like to get done:
clear;clc;close
StartDate = datenum('12-Oct-2012 16:50:00');
EndDate = datenum('12-Oct-2012 17:50:00');
NoOfYAxisDataPoints=20;
NoOfTickMarks=5;
xAxisData = linspace(StartDate,EndDate,NoOfYAxisDataPoints);
yAxisData=linspace(1,25,NoOfYAxisDataPoints);
figure
semilogy(xAxisData,yAxisData)
xTickData = linspace(StartDate,EndDate,NoOfTickMarks);
ax = gca;
ax.XTick = xTickData;
datetick('x','HH:MM','keepticks')
Here both x and y axis data are double type. But how do I accomplish my objective if the x axis data is not double, but datetime type as shown here:
Year = 2012;Month = 10;Day = 12;
Hours = 16;Minutes=(50:5:110)';Seconds= 00;
Time=datetime(Year,Month,Day,Hours, Minutes, Seconds);
figure
plot(Time,linspace(1,25,13))
xTickData = linspace(datenum(Time(1)),datenum(Time(end)),NoOfTickMarks);
ax = gca;
ax.XTick = xTickData;
datetick('x','HH:MM','keepticks')
When I change plot to semilogy, I am getting an error message “Error using semilogy. Non-numeric data is not supported in 'Line'”. But, the documentation of semilogy states that “The values in Xn can be numeric, datetime, duration, or categorical values. The values in Yn must be numeric.”. Even though my x axis values are datetime type, I am getting this error. What am I doing wrong? How do I accomplish this task?
I am using Matlab2016a