Showing information on a plot

Hello,
I am analysing a control system, that has a step input and the given transfer function. I have been able to produce a graph, and obtain the information of the system (Peak, SettlingMax etc.), but I am trying to display this information as shown below on the MATLAB help centre. Unfortunately, I am unable to locate any guidance on displaying the information in this way (see below for my current graph/desired output)
For reference, my transfer function is g = tf(1,[1,8.52,5.3,26]), and as stated prior a step input is used.
This is my blank graph
An example I found in a textbook
And I am looking to display it in this way.
I
Note - I am able to find the values for each of these via the command stepinfo(g), however would like to show them as the nodes on the image above.
Any help to display my results in a similar way would be greatly appreciated!
Thank you,
Lewis

 Respuesta aceptada

Star Strider
Star Strider el 25 de Feb. de 2024
Retrieving and showing all that information is not straightforward, however it is definitely possible. Use stepinfo to get the information, and stepplot to do the plot since it is easier to work with than step.
This should get you started —
g = tf(1,[1,8.52,5.3,26])
g = 1 --------------------------- s^3 + 8.52 s^2 + 5.3 s + 26 Continuous-time transfer function.
si = stepinfo(g)
si = struct with fields:
RiseTime: 0.6338 TransientTime: 28.8675 SettlingTime: 28.8675 SettlingMin: 0.0149 SettlingMax: 0.0682 Overshoot: 77.2255 Undershoot: 0 Peak: 0.0682 PeakTime: 1.9477
figure
hsp = stepplot(g);
Ampl = hsp.Responses.Data.Amplitude;
Time = hsp.Responses.Data.Time;
xl = xlim;
hold on
plot([1 1]*si.PeakTime, [0 si.Peak], '-.k')
plot([0 si.PeakTime], [1 1]*si.SettlingMax, '-.k')
sttmin = interp1(Ampl, Time, si.SettlingMin); % Interpolate To Determine This Specific Time
plot([-1 1]*max(xl)*0.05+sttmin, [1 1]*si.SettlingMin, '-.k')
plot([0 si.PeakTime], [1 1]*si.SettlingMax, '-.k')
hold off
text(si.PeakTime, si.Peak, sprintf('\\leftarrow Peak = %.4f V\n Time = %.4f s', si.Peak, si.PeakTime), 'Vert','middle')
text(max(xl)*0.05+sttmin, si.SettlingMin, sprintf('\\leftarrow Minimum = %.4f V\n Time = %.4f s', si.SettlingMin, sttmin), 'Vert','middle')
% get(hsp)
Tweak appropriately to get the result you want.
.

2 comentarios

Lewis
Lewis el 25 de Feb. de 2024
Thank you!!
Star Strider
Star Strider el 25 de Feb. de 2024
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

the cyclist
the cyclist el 25 de Feb. de 2024

0 votos

You should be able to get everything you want, using the following commands:
title, xlabel and ylabel for the title and axes labels.
line to create the line segments.
annotation to add the text and arrows.

5 comentarios

Lewis
Lewis el 25 de Feb. de 2024
Editada: Lewis el 25 de Feb. de 2024
Thank you, will I have to input the x,y coordinates of each point? Or if for example I say “Peak” will it automatically insert the “bubble” at the peak of the amplitude?
the cyclist
the cyclist el 25 de Feb. de 2024
No, none of this is automatic. You will need to manually create all those additions to your plot.
I assumed that you already knew how to plot the "bubble". You can use the plot or scatter function to plot those. You might need to use the hold command to have both your line plot and the bubbles on the same figure.
Alexander
Alexander el 25 de Feb. de 2024
Not to forget:
text
.
the cyclist
the cyclist el 25 de Feb. de 2024
Yes, the text command is another option. But annotation can do both arrows and textboxes.
Lewis
Lewis el 25 de Feb. de 2024
Thank you, appreciate it!

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Productos

Versión

R2023b

Etiquetas

Preguntada:

el 25 de Feb. de 2024

Comentada:

el 25 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by