0
votes

Hi I am new to MATLAB and need some help with making a matrix so that I can plot a figure of turnover rates on the NYSE. I have 4 vectors right now, year, month, at and mt.

They're uploaded from a .csv in the form of

2010 1 .99 .99
2010 2 .98 .98
2010 3 .99 .98
.    .  .   .
.    .  .   . 
2016 4 .99 .99

I'd like to be able to plot at and mt versus the dates on the x-axis ascending from Jan 2010 to April 2016. Right now I can plot at and mt versus a vector z = 1:76 (as all these vectors are 76x1) just to represent an increasing x.

If anyone can help that'd be awesome. Thanks.

EDIT: Here's my code thus far

year = data(:,1); %Year (2010, 2011...2016)
month = data(:,2); %Month (1,2,3,etc.)
mt = data(:,3); %NYSE Annualized Monthly Turnover
at = data(:,4); %NYSE Annualized Year to Date Turnover

z = 1:76;

a = plot(z, mt, 'r-', z, at, 'b-');
hold on
legend(a, 'Annualized Monthly Turnover NYSE', 'Annualized Year NYSE')
title('Annualized Monthly & Year-to-Date Turnover of NYSE Securities')
xlabel('Date')
ylabel('Turnover (x100%)')
hold off
2

2 Answers

0
votes

You can create a date vector by matlab command datenum, then you can apply the datetick command in plot, such as plot(datetick(vector, 'mm-yyyy'), mt).

0
votes
year = data(:,1); %Year (2010, 2011...2016)
month = data(:,2); %Month (1,2,3,etc.)
mt = data(:,3); %NYSE Annualized Monthly Turnover
at = data(:,4); %NYSE Annualized Year to Date Turnover

z = 1:length(data(:,1));

Convert date values to string

x_axis_val =strcat(num2str (year),'/',num2str(month)); 

plot the graph

a = plot(z, mt, 'r-',z, at, 'b-');
hold on
legend(a, 'Annualized Monthly Turnover NYSE', 'Annualized Year NYSE')
title('Annualized Monthly & Year-to-Date Turnover of NYSE Securities')
xlabel('Date')
ylabel('Turnover (x100%)')

Add tick labels to the axis

set(gca,  'XTickLabel',x_axis_val) %adding x tick labels
hold off