Error using DynamicSystem/step

I'm trying to run a script I wrote that simulates the step response of a time-varying system. To do this, I use:
t=0:.01:.01;
for k=2:500
opt=stepDataOptions('StepAmplitude',e(k));
y=step(feedback(systf,1),t,opt);
t=t+.01;
%y is saved to another variable
%systf is updated
end
When I execute this code, it gives the following error message when k=8:
Error using DynamicSystem/step (line 95)
Attempted to access x(2); index out of bounds because numel(x)=1.
I narrowed it down to the fact that the error does not occur at a specific iteration k, but rather when t=[.06 .07]. If I skip this particular value for t by beginning with
t=[.07 .08], for instance, the program runs until t=[4.00 4.01] (k=395) where it results in the same error message mentioned above. When I open the code for DynamicSystem/step and look at line 95, it just says:
94 catch E
95 throw(E)
I read another question/answer that suggested that DynamicSystem/step is from a 3rd party and not MathWorks. I execute
>> which -all step
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\control\ctrlobsolete\step.m
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\shared\controllib\engine\@DynamicSystem\step.m % DynamicSystem method
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\ident\ident\@iddata\step.m % iddata method
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\matlab\system\@system\step.m % system method
This means that DynamicSystem/step isn't even the highest precedence 'step' function, yet it is still called instead of ...\toolbox\control\ctrlobsolete\step.m.
I am confused as to why this error is occurring and as to why one particular 'step' function is being called over another with supposedly higher precedence. Any help is greatly appreciated, thank you!!

2 Comments

You can debug this further by giving the command
dbstop if caught error
and running.
Reason why the second 'step' was chosen over the first one could be due to the input argument type. With your system object type, the DynamicSystem 'step' is probably the first among the compatible functions to call.
The access to 'x(2)' as mentioned in the message may happen somewhere in the 'try' clause, but with the 'try-catch' structure, debugger will only point to the line when the error is thrown. Try Walter's suggestion of using 'dbstop' or directly putting a breakpoint early in the 'try' clause to step down and identify which line of code is leading to the error.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 17 Jul 2017

Commented:

on 20 Jul 2017

Community Treasure Hunt

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

Start Hunting!