Effacer les filtres
Effacer les filtres

Error: Index in position 2 exceeds array bounds (must not exceed 1).

1 vue (au cours des 30 derniers jours)
Dimitrios Topouridis
Dimitrios Topouridis le 4 Jan 2020
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 commentaires
Sindar
Sindar le 9 Jan 2020
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)?
Walter Roberson
Walter Roberson le 9 Jan 2020
The code doesn't define x

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by