error while running a loop inside transfer function

2 visualizaciones (últimos 30 días)
Kobi
Kobi el 18 de Abr. de 2013
i'm trying to change the value of k from to 0.1:0.1:7 and when i try this i get this error
??? Error using ==> InputOutputModel.subsasgn at 58
Subscript indices must either be real positive integers or logicals.
Error in ==> spect at 7
G(k)=tf([k],[10*10^-3 1]);
my code:
for k=0.1:0.1:7;
G(k)=tf([k],[10*10^-3 1]);
end
how can i fix that?

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Abr. de 2013
You are trying to assign the value of the tf() call into G(k) when k is not an integer. Subscripts must be positive integers.
kvals = 0.1 : 0.1 : 7;
for kidx = 1 : length(kvals)
k = kvals(kidx);
G(kidx) = tf([k],[10*10^-3 1]);
end
  1 comentario
Kobi
Kobi el 19 de Abr. de 2013
ok, but i still don't fully understand what this line does:
k = kvals(kidx);
i'm trying to do the same for all of my program like that:
kvals=0.1:0.1:7; % Change the values of k parameter
for kidx=1:length(kvals);
k=kvals(kidx);
G(kidx)=tf([k],[10*10^-3 1]);
Gtotal(kidx)=feedback(G(k),1);
TAU(kidx)=(G(k).den{1}(1))/(G(k).num{1}(2));
end
and i get this error
??? Error using ==> InputOutputModel.subsref at 44
Subscript no. 2 is out of range.
Error in ==> Untitled at 5
Gtotal(kidx)=feedback(G(k),1);

Iniciar sesión para comentar.

Más respuestas (1)

Kobi
Kobi el 20 de Abr. de 2013
please help i don't understand what am i doing wrong
clear all
clc
kvals=0.1:0.1:7; % Change the values of k parameter
for kidx=1:length(kvals);
k=kvals(kidx);
G(kidx)=tf([k],[10*10^-3 1]);
Gtotal(kidx)=feedback(G(k),1);
TAU(kidx)=(0.01)/(G(k).num{1,1}(2));
end
this thing just won't work.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by