MATLAB: Negative values for ‘ylim’ results in error

axesfigureformatMATLAB

Hi,
i'm trying to use the 'ylim'-commad to specify my axes format. Works fine for positive values, but if 'ylim' turns out to be negative i get the following error is there a way bypass this problem:
axes('box','on',...
'LineWidth',2,...
'FontName','times',...
'FontSize',22,...
'ylim',[0 -1.2],...
'YTick', 0:(-1.2/6) :-1.2,...
'xlim',[0 0.3],...
'XTick', 0:0.3/6:0.3);
results in:
??? Error using ==> axes
Bad property value found.
Object Name : axes
Property Name : 'YLim'
Values must be increasing and non-NaN.
Error in ==> XXXX at 76
axes('box','on',...
Great Thanks!

Best Answer

Hi, if you want to change the direction of the yaxis, you can set 'ydir' to 'reverse'
plot(randn(100,1));
% set(gca,'ylim',[0 -1.2]) gives an error, but
set(gca,'ylim',[-1.2 0]);
set(gca,'ydir','reverse');
is ok.
Wayne