How to make an automated and updated legend for ts step response graph

16 views (last 30 days)
Hi all,
I have developed a scrpit that can calculate step respons for any specified DE.
However, for the legends, it always returns the titles as Fs1.
I wish for the script to return the legend as the range including c1 to c2.
For example:
if c1 = 0
c2 = 5
the legend would show the titles as
c = 0
c = 1
c = 2
c = 3
c = 4
c = 5
Below is the code designed
clear;
close all;
clc;
%% Setting values for the DE %%
I = input("Input value for the numerator in the form [x y z]"); % Sets Numerator Value %
m = input("Input the desired value for m for the denominator of (ms^2 + cs + k)"); % Sets the m value of the Denominator %
c1 = input("Input lowest value of the damping term c"); % Sets the lowest value of the Damping variable c %
c2 = input("Input highest value of the damping term c"); % Sets the highes value of the Damping variable c %
c = c1:c2; % Creates variable c as a (x,y) vector, allowing for multiple damping coeffectients to be used %
k = input("Input the desired value for k for the denominator of (ms^2 + cs + k)"); % Sets valuefor k in the Demoninator of the DE %
%% Calculation and Graphing of DE %%
for j = 1:length(c) % Sets for loop for all damping coefficient variables %
Fs1 = tf([I], [m c(j) k]); % tf calculation using pre-defined variables %
step(Fs1,10) % creates step graph using all values calculated, the time domain is set to 10 seconds for optimisation %
hold on; % holds all data within the loop %
end
hold off % cancels the hold on loop after all values have been saved %
legend

Accepted Answer

Star Strider
Star Strider on 6 Oct 2023
The Control System Toolbox plots are characteristically difficult to work with.
The best option would be:
[y,tOut] = step(Fs1,10);
and then:
figure
plot(tOut, y, 'DisplayName',sprintf('c = %.3f,'c))
or something similar for each parameter variation you are using. Use the hold function to plot different step outputs to the same axes.
With more information or specific data, I could provide a more specific example. As is, I am not certain what result you want.
  4 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!