This question is closed. Reopen it to edit or answer.

problem inside a for loop while trying to change values inside matlab functions

1 view (last 30 days)
Kobi on 21 Apr 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
please help i don't understand what am i doing wrong
clear all
kvals=0.1:0.1:7; % Change the values of k parameter
for kidx=1:length(kvals);
G(kidx)=tf([k],[10*10^-3 1]);
this thing just won't work.

Answers (1)

Rahul Narendra Shanbhag
Rahul Narendra Shanbhag on 18 Jun 2020
Hi Kobi,
I noticed that you are trying to create an array of transfer function variables. However, you have not declared the variable initially. This causes errors since the tf function gives a system model object as output.
Please refer to the section Array of Transfer Function Models in the given document on how to pre-allocate the transfer function array.
Also, you seem to have made syntactical errors in line 7 and 8 of your uploaded code, where you are trying to access the said tf array by using the variable k. However, k is a non-integer and cannot be used as an array index. Array indices must be positive integers.

Community Treasure Hunt

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

Start Hunting!

Translated by