Matlab axes

Herr Kutz

Platinum Member
Jun 14, 2009
2,545
242
106
I'm trying to scale axes in Matlab to a certain size without having to manually change the axes every time I run my simulation. I would like to set the x axes only and leave the y axes as default.

I am using -inf and inf for the yaxis limits because I would like those to stay at default values. However, it changes the y axis limits to the maximum and minimum value of the waveform instead of leaving a little bit of space at the top and bottom when I don't set limits.

Here is a picture that explains what I want a little better:
(the first image shows simulation with no axis settings--but I had to manually change x axis because it keeps showing time longer than my simulation--, the second shows the simulation with axis settings)
matlabhelp.gif


I am using this code:
axis([0 1.2 -inf inf])


Oh yeah, I can't just replace -inf with 0 because I am going to be plotting sinusoidal waveforms too.
 

iCyborg

Golden Member
Aug 8, 2008
1,344
61
91
Can't you find min/max value for y-axis from your data and use it to set y axis, say by adding a fixed value or a percentage? Also, assigning axis to a variable will return xy limits, perhaps you could retrieve them and set a new axis based on those. Unfortunately I don't have Matlab any more, so I can't try it myself...

Instead of -inf you can use 5.. and use 45 instead of inf.
And with another simulation he might need e.g. 10 and 65, and yet another -5 and 30, so he'll have to manually change it every time - exactly what he said he didn't want to do ;)
 

busydude

Diamond Member
Feb 5, 2010
8,793
5
76
And with another simulation he might need e.g. 10 and 65, and yet another -5 and 30, so he'll have to manually change it every time - exactly what he said he didn't want to do

Failed at reading comprehension.