필터 지우기
필터 지우기

How to plot specific variables rather than all of them?

조회 수: 7 (최근 30일)
Brilliant Purnawan
Brilliant Purnawan 2020년 10월 15일
편집: Ameer Hamza 2020년 10월 15일
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