How to create a table using fprintf, and use data from a for loop that uses stepinfo?
Afficher commentaires plus anciens
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!
Réponses (1)
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
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')
C = [fieldnames(INFO) permute(struct2cell(INFO),[1 3 2])].';
fprintf(1, ['%-15s\t' repmat('%f\t',1,numel(INFO)) '\n'], C{:})
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

