How to create a table using fprintf, and use data from a for loop that uses stepinfo?

1 Ansicht (letzte 30 Tage)
Hello, I am trying to make a table using the fprintf function. I am using data from a for loop that I have created show below in the code. Also, the data comes from another function stepinfo. I want to have the columns named: K=1 K=10 K=30 K=50, and the rows equal to the same titles that stepinfo outputs in the command window. If you are able to help it will be most appreciated!
  1 Kommentar
Robert  Flores
Robert Flores am 18 Okt. 2018
I don't know why my code is displaying weird, but here it is in this comment.
clc, clear, close all
% OPEN LOOP
num = {1};
den = {[1 7 10 0]};
Gs = tf(num,den)
output = step(Gs);
figure(1)
stepplot(Gs)
% CLOSED LOOP
for k = [1 10 30 50] % Values from question 3
num1 = {k};
den1 = {[1 7 10 k]};
Gcl = tf(num1,den1)
output1 = step(Gcl);
INFO = stepinfo(Gcl)
figure(2)
stepplot(Gcl)
hold on
end
legend('K=1','K=10','K=30','K=50');
fprintf(1, 'K=1 K=10 K=30 K=50')
fprintf(1, 'DATA', INFO')

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Voss
Voss am 31 Dez. 2023
clc, clear, close all
% OPEN LOOP
num = {1};
den = {[1 7 10 0]};
Gs = tf(num,den)
Gs = 1 ------------------ s^3 + 7 s^2 + 10 s Continuous-time transfer function.
output = step(Gs);
figure(1)
stepplot(Gs)
% CLOSED LOOP
figure(2)
hold on
k = [1 10 30 50]; % Values from question 3
for ik = 1:numel(k)
num1 = {k(ik)};
den1 = {[1 7 10 k(ik)]};
Gcl = tf(num1,den1);
output1 = step(Gcl);
INFO(ik) = stepinfo(Gcl);
stepplot(Gcl)
end
legend('K=1','K=10','K=30','K=50');
fprintf(1, 'K=1 K=10 K=30 K=50')
K=1 K=10 K=30 K=50
C = [fieldnames(INFO) permute(struct2cell(INFO),[1 3 2])].';
fprintf(1, ['%-15s\t' repmat('%f\t',1,numel(INFO)) '\n'], C{:})
RiseTime 20.383617 1.346349 0.589064 0.436029 TransientTime 36.972666 4.527138 9.173444 20.818518 SettlingTime 36.972666 4.527138 9.173444 20.818518 SettlingMin 0.900955 0.901775 0.720177 0.397767 SettlingMax 0.999282 1.121125 1.511893 1.744893 Overshoot 0.000000 12.112479 51.189322 74.489333 Undershoot -0.000000 -0.000000 -0.000000 -0.000000 Peak 0.999282 1.121125 1.511893 1.744893 PeakTime 67.769750 2.978465 1.612894 1.292091

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by