Manipulating "Uncertain" (ureal) plots

8 Ansichten (letzte 30 Tage)
John
John am 27 Jan. 2022
Bearbeitet: Neelanshu am 5 Feb. 2024
I'm using the Robust Control toolbox to plot uss (uncertain parameter) functions creating with ureal.
Using eg Bode() will automatically plots a random collection of outputs from the uncertain transfer function.
1) How can I plot more / fewer plots? The default selection seems to be ~20 plots.
2) I'd like to shade the region that encompasses the plots -- a shaded envelope instead of N line plots.
How can I find the "shell" of a collection of uncertain plots like this? Some more complex uncertain models would intertwine randomly, and there wouldn't be one plot that's "highest" and "lowest", so the outer "shell" (ie not just a high plot and low plot) would be useful.
If this was a time-series, it'd be easier: find the max/min points at each x-axis data tick. Those min/max arrays are the shell.
Does anyone know how to plot a shaded envelope for of a series of Uncertain plots?
% Transfer function (with uncertainty) example
a = ureal('a', 1, 'percent', 50);
s = tf('s');
res = 1 / (s + a);
bode(res);
  2 Kommentare
Star Strider
Star Strider am 28 Jan. 2022
It would likely be best to Contact Support about this. I don’t have the Robust Control Toolbox, however experimenting with it with the online Run feature here as well as bode, I could not determine how to define the various components of ‘a’ or ‘res’ that bode plots, or even collect them as a matrix to plot elsewhere. This would appear to be an undocumented feature that may be available, however is not accessible using the usual handle exploration techniques that I’m used to using.
Please post back here with the solution to this that MathWorks provides.
Include the URL of this thread in your note to Support so that you don’t have to repeat all of this.
.
John
John am 28 Jan. 2022
Thank you for the suggestion :)
Unfortunately I don't have an active service subscription, so I'm unable to contact Mathworks.
I remember when it didn't require a subscription, and it's unfortunate that that's the only contact method, when a product has already been purchased...

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Neelanshu
Neelanshu am 1 Feb. 2024
Bearbeitet: Neelanshu am 5 Feb. 2024
Hi John,
I understand from your query that you are interested to plot fewer or more plots for an uncertain transfer function and obtain a shaded region for the area encompassed by the plots.
To plot more or fewer plots (samples), you can use the "usample" function to generate a number of specific samples from the uncertain system and then plot each of these samples individually as shown in the code snippet below :
% Transfer function (with uncertainty) example
a = ureal('a', 1, 'percent', 50);
s = tf('s');
sys = 1 / (s + a);
%%
N = 8; % or any other number
w = logspace(-2, 2, 200); % Define a frequency range
% Generate N samples
sys_samples = usample(sys, N);
% Plot each sample
fig=figure;
for i = 1:N
bode(sys_samples(:,:,i), 'b', w);
hold on;
end
% Customize the plot as needed
grid on;
title('Bode Plot of Samples from an Uncertain System');
%%
for i = 1:N
[mag(:,i), phase(:,i), ~] = bode(sys_samples(:,:,i), w);
hold on;
end
% Plot the envelope
semilogx(fig.Children(3),w, 20*log10(min(mag,[],2)), 'r--', w, 20*log10(max(mag,[],2)), 'r--');
% Customize the plot as needed
grid on;
title('Envelope of the Bode Magnitude Plot for an Uncertain System');
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
fill(fig.Children(3),[w, fliplr(w)], [20*log10(max(mag,[],2))', fliplr(20*log10(min(mag,[],2))')], 'r', 'FaceAlpha', 0.2);
legend(fig.Children(3),cat(2,repelem("Samples",N), [ "LowerBound", "UpperBound", "Shaded Region"]));
To shade the region that encompasses all the plots (an envelope), you can get the maximum and minimum of the magnitude responses at each frequency among all the samples and then plot it using the "fill" function.
You may refer the following documentation to learn more about "usample" and "bode" functions :
Hope this helps.
  2 Kommentare
John
John am 2 Feb. 2024
Thanks @Neelanshu for the idea...interesting.
I'm trying to understand your fill line method:
fill(fig.Children(3),[w, fliplr(w)], [20*log10(max(mag,[],2))', fliplr(20*log10(min(mag,[],2))')], 'r', 'FaceAlpha', 0.2);
How does this work with the plots? Fill() uses verteces to plot, so how does fliplr() accomplish making a filled region between only the outer plots?
Neelanshu
Neelanshu am 5 Feb. 2024
The "fliplr" function in MATLAB flips the columns of a matrix from left to right, effectively reversing the order of the elements in each row. In the context of plotting, it's often used to create a continuous loop around data points that can be filled with a color or pattern to create a shaded region.
The "fill" function in MATLAB takes a set of x and y coordinates and fills the enclosed area with a specified color and properties. When using "fill" to create a shaded region between two lines on a plot, you would typically pass the x-coordinates concatenated with their flipped version (to go back to the starting point) and do the same with the y-coordinates for the upper and lower bounds of the shaded region.
You may refer to the following documentation to learn more about the "fill" function:
Hope this helps.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by