Why "Index in position 2 exceeds array bounds." ?

Hey guys,
i wanted to identify system parameters of a DC-Motor with Simulink and two matlab scripts. The scripts I want to use, should use the least square error and optimise params with fminsearch.
This is my IdentifyMotor.m file:
clear; close all
global t velocity K T1 T2 k
load Sprungantwort_Encodermotor.txt
velocity = Sprungantwort_Encodermotor(1:800);
t = (0:length(velocity)-1)*100e-6;
clear Sprungantwort_Encodermotor
plot(t, velocity)
grid
xlabel('time [usec]')
ylabel('velocity')
K = 800;
T1 = 2;
T2 = 1;
figure(2)
hold
k = 0;
p = [T1 T2]
options = optimset('MaxFunEvals', 60);
p = fminsearch('SumSquareErrors', p, options)
figure (2)
hold
This is the SumSquareErrors.m :
function summe = SumSquareErrors(p)
global t velocity simResponse K T1 T2 k
T1 = abs(p(1))
T2 = abs(p(2))
if T1 < 0.01
T1 = 0.01
end
if T2 < 0.01
T2 = 0.01
end
sim('SimSystem')
figure(1)
plot(t,velocity,simResponse(:,1),simResponse(:,2),'r')
grid
xlabel('time [usec]')
ylabel('velocity')
title('system identificaion')
q = velocity-simResponse(:,2);
summe = sum((q.^2))
figure(2)
k=k+1;
plot(k,summe,'*')
The errors i get are the following:
Index in position 2 exceeds array bounds.
Error in SumSquareErrors (line 13)
plot(t,velocity,simResponse(:,1),simResponse(:,2),'r')
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in IdentifyMotor (line 19)
p = fminsearch('SumSquareErrors', p, options)
The problem i have is that simResponse doesn't show up in my Workspace while im running those scripts. But it is declared in the Simulink-Model and also in the SumSquareErrors file. I tried to work with toWorkspace-Blocks but that didn't helped either...
Can anyone help me?

2 个评论

Can you set a breakpoint at that line? Then try this
>> whos simResponse
Evidently simResponse has only one column.
thank you! I debugged the script and noticed that i assigned simResponse the wrong way

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Simulink Functions 的更多信息

产品

版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by