Add values from vector to plot title

조회 수: 10 (최근 30일)
Daniel
Daniel 2023년 8월 3일
편집: VBBV 2023년 8월 3일
How do I add values from zeta and omega to the plot title with commas between the values?
Current code only displays the last value in the array.
Appreciate the help
clear
s = tf('s');
zeta = input('Enter damping ratio values in a 1D array: ');
omega = input('Enter natural frequency values in a 1D array: ');
stop = input('Enter stop time: ');
figure;
hold on;
for n = 1 : length(omega)
Gs = omega(n)^2 / ((s^2) + (2*zeta(n)*omega(n)*s) + omega(n)^2);
step(Gs, stop);
end
hold off;
title({['Unit Step Response of G(s) = \omega_{n}/(s^2 + 2\zeta\omega_{n}s + \omega_{n}^2)'], ...
['\zeta = ', num2str(zeta(n)), ' and \omega_n = ', num2str(omega(n))]});
ylabel('System Response');

답변 (1개)

VBBV
VBBV 2023년 8월 3일
편집: VBBV 2023년 8월 3일
title({['Unit Step Response of G(s) = \omega_{n}/(s^2 + 2\zeta\omega_{n}s + \omega_{n}^2)'], ...
     ['\zeta = ', num2str(zeta(n)), ' and \omega_n = ', num2str(omega(n))]});
ylabel('System Response');
hold on
  댓글 수: 1
VBBV
VBBV 2023년 8월 3일
편집: VBBV 2023년 8월 3일

Put the entire title command inside the for loop and better to use subplot command to plot individually for each iteration of the for loop

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by