Reputation: 6668
I am trying to plot a chart in MATLAB. I have read that datetick is the way to go however I cannot get it to work. The error message is below the example of my code. te_result_struct.comp_dates is a vector containing the dates in a number format. If I plot the chat without trying to format the dates everything works.
figure(1)
plot(te_result_struct.comp_dates, te_result_struct.te_diff)
datetick(te_result_struct.comp_dates, 12)
SWITCH expression must be a scalar or string constant.
Error in datetick>parseinputs (line 352) switch v{1}
Error in datetick (line 109) [axh,nin,ax,dateform,keep_ticks,keep_limits] = parseinputs(varargin);
Error in tracking_error_comp_ret (line 74) datetick(te_result_struct.comp_dates, 12)
Upvotes: 0
Views: 263
Reputation: 46365
The first argument of datetick
is the axis to which you are applying, not the values of the labels. Try
datetick(gca,12);
This uses the built-in pre-defined "format 12" which is 'mmmyy'
- see http://www.mathworks.com/help/matlab/ref/datetick.html
Upvotes: 2