"index exceeds matrix dimensions" using simulink

7 Ansichten (letzte 30 Tage)
Osmar Sanchez
Osmar Sanchez am 18 Feb. 2020
Beantwortet: Sai Sri Pathuri am 26 Feb. 2020
the following code is in regards to rotational sytem with three storing elements using simulink to plot for angular velocities an torque. after y_out(:,1) however, it keeps showing that the index exceeds matrix dimensions. Any help? simulink file is attached
clc
clear all
m1=1;
m2=3; %this is the mass in kg
k=330;
r1=.03;
r2=.1;
b=.2;
J1=.5*m1*r2^2;
J2 = J1;
N=r2/r1;
A = [0 1 -1 ;-k/J1 0 0; k/J2 0 -b/J2];
B = [0 ; N/J1 ;0];
C=[0 0 1];
D=[0]';
x0= [0]';
tf=30;
t1 = [0:0.01:tf];
%t1 = [0:0.01:1]
F = 10 ;
u=F*ones(size(t1));
%u=F*cos(t1)
sim('HW2_SimLink')
cart_po = y_out(:,1);
cart_vel = y_out(:,2);
cart_po1 = y_out(:,3);
cart_vel1 = y_out(:,4);
figure(1)
plot(t1,cart_po,'-b','linewidth',1.5)
xlabel('Time (seconds)','fontsize',14)
ylabel('Position m1 (m)','fontsize',14)
grid,
figure(2)
plot(t1,cart_vel,'-r','linewidth',1.5);
%legend('Position','Velocity')
xlabel('Time (seconds)','fontsize',14)
ylabel('Velocity m1 (m/s)','fontsize',14)
grid, hold
figure(3)
plot(t1,cart_po1,'-g','linewidth',1.5)
xlabel('Time (seconds)','fontsize',14)
ylabel('Position m2 (m)','fontsize',14)
grid, hold
figure(4)
plot(t1,cart_vel1,'-k','linewidth',1.5);
%legend('Position','Velocity')
xlabel('Time (seconds)','fontsize',14)
ylabel('Velocity m2 (m/s)','fontsize',14)
grid, hold

Antworten (1)

Sai Sri Pathuri
Sai Sri Pathuri am 26 Feb. 2020
The model is generating an output y_out of size 5099x1 (i.e., 5099 rows and 1 column). But you are trying to access 2nd, 3rd and 4th columns which does not exist.

Kategorien

Mehr zu General Applications 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!

Translated by