Bodeplot with XLim option does not rescale y-axis in R2024b

7 views (last 30 days)
Hi,
I am using MATLAB on ubuntu 24.04. I recently updated from MATLAB 24a to 24b. After the update I have the following problem:
I use bodeoptions() (from control systems toolbox) with XLim option set to the frequency range of bodeplot(). I want the y-axis the be auto scaled to the data. It worked like this in R24a, however now the y scale is not updated for the XLim which is set. This is quite anoying as I always have to zoom in on the plots. How can I fix this?
To recreate run:
s = tf("s");
G = 1/s*exp(-0.1*s);
opts = bodeoptions;
opts.XLim = [1, 100];
bodeplot(G, opts);
Then one can see that both the phase and magnitude y-axes should be rescaled.

Accepted Answer

Andrew Ouellette
Andrew Ouellette on 7 Feb 2025
Hello Tor,
This is a side effect of the update to charts in R2024b. The chart's Y limits are no longer linked to its X limits. To achieve the effect you desire, you should instead limit the frequency range of the response data like below.
s = tf("s");
G = 1/s*exp(-0.1*s);
bodeplot(G, {1 100});
  11 Comments
Andrew Ouellette
Andrew Ouellette on 10 Feb 2025
Hi @Paul,
There is a difference for users between plotted and displayed data.You are correct that more data is plotted than what is displayed by default. You can see this additional data by panning or zooming out on the chart, which is equivalent to changing the XLimits and/or YLimits properties.
To explain the vagueness of "the entire range of the plotted data," let's take a simple integrator system (1/s) as an example. At w=0, the gain is infinite, and at w=Inf, the gain is 0 (or -Inf dB). Clearly, we can't plot the frequency response over the entire region [0,Inf] x [-Inf,Inf] on any finite computer screen. Instead, we use either the user-provided frequency specification or some heuristics to pick an "interesting" frequency range [wmin,wmax] and then compute the corresponding minimum/maximum gains & phases in that interval. Those become the automatic limit values corresponding to "the entire range of the plotted data". Although, we do still plot the frequency response at frequency points beyond that range by default, so perhaps the "the entire range of the plotted data" is a bit misleading.
As to why using bodeoptions sets more properties than just the XLimits, the bodeoptions object does not track which properties a user has modified. The chart has no choice but to take the entire object at "face value", and map each of the options properties to the corresponding chart property. This causes the chart fonts to change if you did not create the bodeoptions object using the 'cstprefs' flag, since the chart applies the user preferences by default unlike the options object.
Lastly, Tor is correct in that the legend error results from the 'Interpreter' name-value pair being specified. Walter is right in that we do not explictly document passing legend names using cell arrays of strings (we only document cell arrays of character arrays and string arrays), but currently our input parser is able to account for the undocumented cell array of strings case.
Paul
Paul on 11 Feb 2025
Edited: Paul on 11 Feb 2025
I think I'm following all of this, though I think it would be better to not use "plotted" and "displayed" to mean two very different things. Perhaps "computed" and "displayed" would be better terminology. So I guess that setting the XLim now has no bearing on the limits of the computed data, which are now based only on the user-specified [wmin,wmax] or the heuristic. Still unclear to me how the limits are selected for the displayed data (if not specified by the user) insofar as the displayed data has different limits than the computed data.
I'm still not following the font changes. Why aren't the three cases below the same?
My image is that Case 1 uses the default plotoptions because no other was specified. Is that not the case? If it isn't, then what plotoptions are being used in Case 1?
Case 2 uses the default plotoptions explicitly, which should be the same as Case 1(from a user perspective), but it isn't.
Case 3 uses the "the plot options with the options you selected in the Control System Toolbox™ ... preferences editor." But I haven't run ctrlpref here, so it seems like I should be just getting back the same plotoptions object as used for Case 2. But, Case 3 is actually the same as Case 1.
From a user perspective, based on my current understanding, I think that all three of these cases should yield the same results as they should all be based on the same default settings, whatever they may be.
s = tf("s");
G = 1/s*exp(-0.1*s);
% Case 1
figure
bodeplot(G)
% Case 2
figure
bodeplot(G,bodeoptions)
% Case 3
figure
bodeplot(G,bodeoptions('cstprefs'))
If I had changed the local preferences using ctrlpref, then I would expect that those would be used for all three of these cases. As it stands, it sounds like if I do have local preferences defined (after using ctrlpref), they are completely ignored unless I force them into action using bodeoptions('cstprefs'), which seems counter to the whole point of setting preferences via ctrlpref in the first place.
As it turns out, the defaults for bodeoptions are not the same as the defaults for bodeoptions('cstprefs')
opts1 = bodeoptions;
opts2 = bodeoptions('cstprefs');
isequal(opts1,opts2)
ans = logical
0
opts1.Title
ans = struct with fields:
String: 'Bode Diagram' FontSize: 8 FontWeight: 'Normal' FontAngle: 'Normal' Color: [0 0 0] Interpreter: 'tex'
opts2.Title
ans = struct with fields:
String: 'Bode Diagram' FontSize: 11 FontWeight: 'bold' FontAngle: 'normal' Color: [0 0 0] Interpreter: 'tex'
So the explains the difference between Case 2 and Case 3, and Case 1 looks like it uses bodeoptions('cstprefs') under the hood. But that naturally leads to the question of why bodeoptions and bodeoptions('cstprefs') return different results when no action was taken to modify the default preferences in the first place.

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!