changing the x axis candle stick chart
7 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
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
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
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!