changing the x axis candle stick chart

조회 수: 7 (최근 30일)
AA
AA 2016년 11월 4일
댓글: Nick Counts 2016년 11월 9일
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.

채택된 답변

Nick Counts
Nick Counts 2016년 11월 6일
편집: Nick Counts 2016년 11월 6일
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 :)
  댓글 수: 5
Nick Counts
Nick Counts 2016년 11월 9일
AA, I think it would be really helpful if we could see a sample of NewMATRIX2. Do you mean that the first column is minutes and the second column is the serial date (as in, the output of Matlab's datenum)?
And forgive me if this sounds condescending, as it is not my intention, but do you intend to use duration objects and datetime objects?
If you don't need the class methods, it may be much simpler (and clearer) to use good-old serial dates, which are just represented as doubles and are supported by virtually all of Matlab's plotting functions (including candle)
Unfortunately, I can't run your sample code without guessing at what NewMATRIX2, date_num, and numOnly are.
This is my new guess:
Based on your previous question regarding importing excel times, I suspect this all stems from trying to get a usable representation of a timestamp (I will use timestamp to mean date and time) that you can use as the x-axis variable in your candle plot and also to specify the labeling of the x-axis on your plot.
Please post an example of your input (whatever variables you are starting with). It would also be very helpful to include sample code that we can copy-paste and run. You can include a sample variable like:
NewMATRIX2 = [736613, 60;
736614, 78;
736615, 42;
736616, 124;
736617, 256;
736618, 38]
We can get figure this out, we just need to know a little more :)
Nick Counts
Nick Counts 2016년 11월 9일
This is an educated guess based on your other questions:
clear
inputArray = {
'Mon, Apr-25-16' 0.0763888888888889;
NaN NaN;
'Mon, Apr-25-16' 0.0763888888888889;
'Fri, Mar-25-16' 0.0347222222222222;
'Wed, Feb-24-16' 0.0347222222222222;
'Tue, Jan-26-16' 0.0347222222222222;
'Fri, Dec-25-15' 0.0347222222222222;
'Wed, Nov-25-15' 0.0347222222222222;
};
% Get rid of nan
rowsToRemove = isnan([inputArray{:,2}]');
inputArray(rowsToRemove,:) = [];
dateMatrix = datevec(inputArray(:,1),'ddd, mmm-dd-yy');
% make the Matlab serial date
timeStamp = datenum(dateMatrix);
% Add the 'time' portion, which is a fraction of a day
timeStamp = timeStamp + [inputArray{:,2}]' ;
% build a set of example stock data (doubles)
col1 = randi(100, 7, 1);
col2 = randi(100, 7, 1);
col3 = randi(100, 7, 1);
col4 = randi(100, 7, 1);
% candle plot with x-ais date argument from cell array of strings
candle( col1, ...
col2, ...
col3, ...
col4, ...
'b', ...
timeStamp, ...
'dd/mm/yy');

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Nick Counts
Nick Counts 2016년 11월 4일
편집: Nick Counts 2016년 11월 4일
try dateaxis
load disney;
candle(dis_HIGH(end-20:end), ...
dis_LOW(end-20:end), ...
dis_CLOSE(end-20:end),...
dis_OPEN(end-20:end), 'b');
dateaxis;
There are options for how the dates are displayed, see the documentation
Good luck!

AA
AA 2016년 11월 5일
no, datetick wont allow me to insert my prespecified x-axis (variable tt). is there any other way to integrate this?

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by