MATLAB Answers

what is the reason of an empty diagram?

10 views (last 30 days)
Tina M
Tina M on 22 Feb 2021
Commented: Star Strider on 22 Feb 2021
I wrote a code in state space(I chose 10 state variables) and after using ode45 I want to plot xdot(10) that I defined it in function part.but when I run , it shows an empty diagram. can anybody help me solving this problem?
clc;clear;close all;
x0=[0;0;0;0;0;0;0;0;0;0];
t_sim=linspace(0,5,100);
k_ss=111177; %N/m
c_ss=3858.82; %N.m
k_s1=10000; %N/m
c_s1=1264.71; %N.m
k_s2=10117.7; %N/m
c_s2=1852.94; %N.m
r=0.49804; %m
l_1=1.011; %m
l_2=1.803; %m
m_1=40; %kg
m_2=35.5; %g
m_s=730; %kg
m_c=75; %kg
I_s=130; %kg.m^2
k_p1=175500; %N/m
k_p2=175500; %N/m
[t,x]=ode45(@func,t_sim,x0);
xdot=zeros(10,1);
xdot(10)=-(1/m_c)*(k_ss*(x(9)-x(5)+r*x(7))+c_ss*(x(10)-x(6)+r*x(8)));
plot(t,xdot(10));
%%
function xdot=func(t,x)
.
.
.
.

Accepted Answer

Star Strider
Star Strider on 22 Feb 2021
It is likely necessary to index the variables appropriately.
Try this:
xdot10=-(1/m_c)*(k_ss*(x(:,9)-x(:,5)+r*x(:,7))+c_ss*(x(:,10)-x(:,6)+r*x(:,8)));
Then:
plot(t, xdot10)
should work.
Since ‘func’ is not provided I cannot test this, so I am posting it as UNTESTED CODE.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!