How to plot specific variables rather than all of them?
21 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/381773/image.png)
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);
0 Commenti
Risposte (1)
Ameer Hamza
il 15 Ott 2020
Modificato: Ameer Hamza
il 15 Ott 2020
You can specify the column you want to plot
plot(t, y(:,1)); % using t as x-axis is more useful
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!