This works for the first two of the subplots, but not the bottom (last one). For some reason the y-axis ignores the values I set using set(gca, 'YLim', [ min max ]), which are the same values I have been using for the previous subplots.
If I set the values manual (ie. without first determining the values by parsing the datasets) then the YLim function works fine. So, I feel like the problem is that maybe the type is wrong in the set YLim command? The YLim values are pulled from a vector, and I print them out, and they seem correct. It is most odd.
Here is an example:
% my_y_vals is populated from my data queries:
my_y_vals = [ 1.245 10.345 4.656 ]
% I get the maximum value from this to use as the YLim max and min for each subplot
my_max_y = max(abs(my_y_vals))
my_min_y = my_max_y * -1
figure(1)
% Loop for subplots
for i=1:3,
my_subplot = subplot(3,1,i)
% Bunch of code to get datapoints and then plot them
plot(timevals,data)
% Now set the limits on the Y-axis
set(gca, 'YLim', [my_min_y my_max_y])
% If I switch it out with the following, it works fine
% set(gca, 'YLim', [-20 20])
end
Does anyone have any insight on this? I feel like it is just a simple type casting problem - maybe I need to switch the type to a string or float or something?
Thanks in advance.
*snip*
> % Loop for subplots
> for i=1:3,
>
> my_subplot = subplot(3,1,i)
>
> % Bunch of code to get datapoints and then plot them
> plot(timevals,data)
>
> % Now set the limits on the Y-axis
> set(gca, 'YLim', [my_min_y my_max_y])
Are you certain that gca is the axes you intend to work on? You already
_have_ the handle to the axes -- it's my_subplot. What happens if you use
that in place of gca in your code?
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
a hint:
% replace
set(gca,'YLim',[my_min_y my_max_y])
% with
set(my_subplot,'YLim',[my_min_y my_max_y]);
us
Best regards.
When you are working with multiple axes, such as via subplot(), unless you
have specifically activated a particular axes, you should not assume that it
is active.
ylim works on a per-axes basis, so if you activate it against the wrong axes,
you are not going to get the result you want.