MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Locks
on 29 Apr 2013

hi,

I have this code:

dates=datenum(VIXdate)

y=VIX

plot(dates,y)

%datevc divides the date in different columns, first colum is the year, %second the month and thrid the day d=datevec(dates)

%Takes just the year (first column) d=d(:,1)

%takes every year just once [a,idx]=unique(d(:,1),'first')

ylabel('VIX');

set(gca,'xtick',dates(idx),'xticklabel',a)

set(gca,'Box','off')

this works fine, but the problem I faces is that the time series (y=VIX) does not start at the left end of the plot but instead there is a space between the y-axis and the first point of the time series. I know that when there are normal values on the x-axis, I can change it, but I am not able to do it with dates, what do I need to do?

*No products are associated with this question.*

Answer by Jonathan Epperl
on 2 May 2013

Accepted answer

This is still not a working example, the variable `VIXdate` is obviously unknown to us...

So the dirty way again:

ytix = get(gca,'YTick'); set(gca,'YTick',ytix(2:end));

Locks
on 2 May 2013

perfect, thanks

I have another similar problem with this code here:

dates=datenum(dataSet(:,1));

%SPX SPX=dataSet(:,2);

%VIX VIX=dataSet(:,3);

plotyy(dates,SPX,dates,VIX);

d=datevec(dates); d=d(:,1);

[a,idx]=unique(d(:,1),'first');

ylabel('S&P 500 Index') %axis([ 0 2000]); set(gca,'xtick',dates(idx),'xticklabel',a) set(gca,'Box','off')

here it shows me on the xaxis both the date as well as the date in numerical form, how can I change that?

Also I would like to change the color from both y axis into black, is that possible?

Jonathan Epperl
on 2 May 2013

You should make that a new question, and finally make it so that we can copy and paste your code into our matlab and run it and see what it is you want to achieve.

Answer by Mel
on 1 May 2013

You could also set just the x axis to be the same as your data:

xlim([0 max(dates)])

Answer by Jonathan Epperl
on 29 Apr 2013

axis tight

Locks
on 1 May 2013

that is working, but I am only looking for that for the x axis but not for the y axis, is that also possible?

Jonathan Epperl
on 1 May 2013

Sure. Without knowing what your actual data looks like (it would still be nice if you could post a working minimal example), you could do that:

ylims = get(gca,'YLim'); axis tight set(gca,'YLim',ylims);

Dirty, but should work.

Locks
on 1 May 2013

dates=datenum(VIXdate) y=VIX plot(dates,y)

d=datevec(dates)

%Takes just the year (first column) d=d(:,1)

%takes every year just once [a,idx]=unique(d(:,1),'first')

ylabel('VIX');

set(gca,'xtick',dates(idx),'xticklabel',a)

ylims = get(gca,'YLim'); axis tight set(gca,'YLim',ylims);

set(gca,'Box','off')

it's working perfectly now, thanks!

in addition, it would be great if the number 0 on the y axis is not shown in the plot due to the fact that it's so near to the numbers on the x axis, is there a way to do that?

## 1 Comment

## Babak

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/74023#comment_146209

Undefined function or variable 'VIXdate'.