필터 지우기
필터 지우기

Plot Matix

조회 수: 2 (최근 30일)
Trader
Trader 2012년 3월 23일
I'm trying to plot a 539x13 matrix with the first column = dates which are in cell format. Everything else in the array is a double value.
How can I plot columns 2 to 13 using the date values as my tick values?
when I try setting:
set(gca,'XTickLabel',p_day)
I get the error:
Error using ==> set Cell array of strings may only contain string and numeric matrices
Your help is greatly appreciated!

채택된 답변

Trader
Trader 2012년 3월 26일
In case someone has the same problem, you must convert the date using datum()
here is the code I used:
date = datenum(date, 'yyyy-mm-dd'), 'mmddyyyy'; plot(date, p_open) set(gca,'XTickLabel',date) datetick('x','mm-dd-yyyy','keepticks')
Thanks Jan for the suggestion. I'm not sure why but the labels are broken into about 2 month periods (there are 3 points where it is a 1 month period)

추가 답변 (2개)

Rick Rosson
Rick Rosson 2012년 3월 23일
Please post your code.
  댓글 수: 1
Trader
Trader 2012년 3월 23일
file_name = 'spy_01012010_now.csv';
file_dir = 'Historical_data/';
full_path = [file_dir,file_name];
file_out = [file_dir,'output_',file_name];
import1 = importdata(full_path);
% the first column (starting from the second row) is the trading days in format mm/dd/yyyy.
date = import1.textdata(2:end,1);
% Create OHLC matricies
price_open=import1.data(:,1);
price_high=import1.data(:,2);
price_low=import1.data(:,3);
price_close=import1.data(:,4);
for loop using import data to fill a matrix called xls_full_data that is 539x13 but for example sake the matrix is filled like this:
xls_order_data(x,:) = {current_date open high low close};
where x is an int used for a counter, current_date = current_date = char(date(i)); and open = price_open(x); high = price_high(x); etc...
then i try to plot using:
p_day = cell2mat(xls_full_data(1:end,1));
p_open = cell2mat(xls_full_data(1:end,2));
p_high =cell2mat(xls_full_data(1:end,3));
p_low = cell2mat(xls_full_data(1:end,4));
p_close = cell2mat(xls_full_data(1:end,5));
this doesn't work:
plot(p_day,p_open)
set(gca,'XTickLabel',p_day)
Like I said before, I'd like to use the date values for the tick then plot open, high, low and close.
Thanks for your help!

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


Jan
Jan 2012년 3월 23일
Perhaps:
set(gca, 'XTickLabel', p_day(:, 1))
But this is guessing only. Please post the code and a small example of the values. I do not think, that 539 labels will look nice.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by