Why "Index in position 2 exceeds array bounds." ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 4 Aug. 2019
Can you set a breakpoint at that line? Then try this
>> whos simResponse
Evidently simResponse has only one column.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!