How to plot specific variables rather than all of them?

24 次查看(过去 30 天)
Hi, quite new to MATLAB and ran into some problems with plotting a specfici variable. Below the code is for the dynamics of a pendulum, made by Steve Brunton. My problem here is that I can't seem to refer to a certain variable, everytime I try to it just plot me all the graphs. Refer to the plot below, as you can see it plots all the variable within the function file, and If I try to plot only one part of it, it just return me an error message. See below for the full code.
This is the function file code:
function dx = PendEx(x,m,M,L,g,d,u)
Sx = sin(x(3));
Cx = cos(x(3));
D = m*L*L*(M+m*(1-Cx^2));
dx(1,1) = x(2);
dx(2,1) = ((m*L*g*Sx*Cx)-u*L+d*x(2)*L-m*L^2*x(4)^2*Sx)/(-(M+m)*L+m*L*Cx^2);
dx(3,1) = x(4);
dx(4,1) = (u*Cx-d*x(2)*Cx+m*L*x(4)^2*Sx*Cx-g*Sx*(M+m))/(L*(-M-m+m*Cx^2));
This is the script, as you can see the plot above is generated from just using the plot(y); I have alrady tried plotting certain the variables specifically but its not working. So any help is appreciated. My overall plan is to change the four plots into 4 different graphs. Thanks!
clear all, close all, clc
m = 0.25;
M = 0.635;
L = 0.5;
g = -10;
d = 1;
tspan = 0:.1:50;
y0 = [0; 0; pi; .5];
[t,y] = ode45(@(t,y)PendEx(y,m,M,L,g,d,0),tspan,y0);
plot(y);

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-10-15
编辑:Ameer Hamza 2020-10-15
You can specify the column you want to plot
plot(t, y(:,1)); % using t as x-axis is more useful

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by