Filter löschen
Filter löschen

Plot Matix

2 Ansichten (letzte 30 Tage)
Trader
Trader am 23 Mär. 2012
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!

Akzeptierte Antwort

Trader
Trader am 26 Mär. 2012
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)

Weitere Antworten (2)

Rick Rosson
Rick Rosson am 23 Mär. 2012
Please post your code.
  1 Kommentar
Trader
Trader am 23 Mär. 2012
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!

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 23 Mär. 2012
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.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by