MATLAB: Changing the x axis candle stick chart

datetime array

drawing this candle stick chart gives me the following error
candle(col2,col3,col4,col1,'b',tt,'dd-MM-yyyy HH:mm:SS')
Error using candle (line 132) Function 'subsindex' is not defined for values of class 'cell'.
I just want the the x-axis of the candle stick chart to show the dates which i have saved in a datetime array.

Best Answer

Sorry, it looks like I misunderstood your issue. Without seeing what your variables are (data types, sizes, etc) it's a little tricky to debug your code, but here is an example with two approaches that should help:
% Load Sample Data
load disney;
% Build a vector of datenums for the x axis
dateNumVector = floor(now)-20:floor(now)-10;
dateNumVector = dateNumVector'; % Must be a column vector
% Method 1: Using a datenum array:
fh1 = figure;
% candle plot with the x-axis datenum argument
candle( dis_HIGH(end-20:end-10), ...
dis_LOW(end-20:end-10), ...
dis_CLOSE(end-20:end-10),...
dis_OPEN(end-20:end-10), ...
'b', ...
dateNumVector);
% Method 2: Using datetime object array
fh2 = figure;
% build an example datetime object array:
dateTimeArray = datetime(datestr(dateNumVector));
% candle plot with x-ais date argument
candle( dis_HIGH(end-20:end-10), ...
dis_LOW(end-20:end-10), ...
dis_CLOSE(end-20:end-10),...
dis_OPEN(end-20:end-10), ...
'b', ...
dateTimeArray.Day);
Note that in your sample line of code, if class(tt) is datetime then you have to use the Day method to pass dates in the form candle is expecting.
Hopefully this will get you sorted out :)