Error: Index in position 2 exceeds array bounds (must not exceed 1).
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
i have a problem with my code, specifically with my animation output.
As soon as the code gets to line 500, where the animation part is, i get the error from the title with the following added:
" Index in position 2 exceeds array bounds (must not exceed 1).
Error in sym/subsref (line 890)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in A33Meins (line 501)
animation4(t,x(:,1:13),.05,{fh_boden_fix boden_fix 4;..."
Here is my code :
%% Animation:
boden_fix = {[-1.25 0 0;
1.25 0 0]};
boden_u = {[0.9 0 0;
1.2 0 0]};
karosserie_1 = {[-p.a/2 -p.hs 0;
p.a/2 -p.hs 0;
p.a/2 p.hs 0;
-p.a/2 p.hs 0;
-p.a/2 -p.hs 0]};
hebel_2 = {[ 0 0 0;
p.be 0 0]};
hebel_3 = {[ 0 0 0;
-p.be 0 0]};
hebel_5 = {[ 0 0 0;
-p.b5 0 0]};
hebel_7 = {[ 0 0 0;
p.b5 0 0]};
koerper_4 = {[ 0 0 0;
-p.b4/2 p.hs4 0;
p.bc p.hs4 0;
p.bc -p.hc4 0;
p.bc p.h4 0;
p.bc p.hs4 0;
-p.b4/2 p.hs4 0;
-p.b4 p.h4 0]};
koerper_6 = {[ 0 0 0;
p.b4/2 p.hs4 0;
-p.bc p.hs4 0;
-p.bc -p.hc4 0;
-p.bc p.h4 0;
-p.bc p.hs4 0;
p.b4/2 p.hs4 0;
p.b4 p.h4 0]};
fh_boden_fix = @(t,x)deal([0;0; 0],[1,0,0;0,1,0;0,0,1]);
fh_boden_u = @(t,x)deal([0;u_von_t(t);0],[1,0,0;0,1,0;0,0,1]);
fh_karosserie_1 = matlabFunction(I_r_OS1,A_IK1, 'vars', {t, q});
fh_hebel_2 = matlabFunction(I_r_OA, A_IK2, 'vars', {t, q});
fh_hebel_3 = matlabFunction(I_r_OB, A_IK3, 'vars', {t, q});
fh_hebel_5 = matlabFunction(I_r_OF, A_IK5, 'vars', {t, q});
fh_hebel_7 = matlabFunction(I_r_OJ, A_IK7, 'vars', {t, q});
fh_koerper_4 = matlabFunction(I_r_OE, A_IK4, 'vars', {t, q});
fh_koerper_6 = matlabFunction(I_r_OI, A_IK6, 'vars', {t, q});
%% numerische Integration:
t_start = 0;
t_end = 4;
x0 = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % Anfangswerte erweitern
options = odeset('RelTol',1.e-4,... % Standard 1.e-3
'AbsTol',1.e-7,... % Standard 1.e-6
'OutputFcn',@odeplot);
h=figure;
tic
[t,x_] = ode23(@ode_fcn,[t_start t_end],x0,options);
toc
close(h);
% q_pp bestimmen:
for i=1:length(t)
x__p(i,:)=ode_fcn(t(i),x_(i,:)');
end
q = x_(:, 1:p.n);
q_p = x_(:, (p.n+1):p.n*2);
q_pp = x__p(:,(p.n+1):p.n*2);
% Beschleunigung in P:
for i=1:length(t)
a_p(i,:)=p.fhandle_ap(q(i,:)',q_p(i,:)',q_pp(i,:)')';
end
% Animation
figure;
animation4(t,x(:,1:13),.05,{fh_boden_fix boden_fix 4;...
fh_boden_u boden_u 4;...
fh_karosserie_1 karosserie_1 3;...
fh_hebel_2 hebel_2 2;...
fh_hebel_3 hebel_3 2;...
fh_koerper_4 koerper_4 2;...
fh_hebel_5 hebel_5 2;...
fh_koerper_6 koerper_6 2;...
fh_hebel_7 hebel_7 2},[0,90]);
2 件のコメント
Sindar
2020 年 1 月 9 日
This error message is telling you that you are trying to index an element that doesn't exist. The first thing I'd do in this case is debug the code (https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html), pausing just before line 501. Then, run
size(x)
More specifically, are you sure it shouldn't be x_(:,1:13)?
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!