MATLAB: Error while running a loop inside transfer function

MATLABmatlab transfer function error loop for tf

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?

Best Answer

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