How to remove dashed vertical line in graph
이전 댓글 표시
Hello,
I am graphing a series of trajectories (and their velocities and acceleraitons) however I am getting an odd vertical dashed line (that is not plotted, it is just there). It wouldn't be a huge problem but it overtlaps and obscures directly on a vertical line of a jump disontinuity. The line goes away after dragging the graph over a bit but this is undesirable. It is also odd that it only occurs on the first subplot.

Code is given below (sorry for length):
clear all;
clc;
syms t real;
% Position in [deg deg m]
q_0 = [0 0 0]';
q_1 = [-8 45 0.2]';
q_2 = [-90 90 0.4]';
% Speeds in [deg/s deg/s m/s]
q_dot_0 = [0 0 0]';
q_dot_1 = [10 40 0.2]';
q_dot_2 = [0 0 0]';
% Times in s
t0 = 0;
t_1 = 2;
t_2 = 4;
coefficients = zeros(2,4,3);
% Segment 1: 0 < t < 2
coefficients(1,:,1) = cpsCoefficients(q_0(1), q_1(1), q_dot_0(1), q_dot_1(1), t0, t_1);
coefficients(1,:,2) = cpsCoefficients(q_0(2), q_1(2), q_dot_0(2), q_dot_1(2), t0, t_1);
coefficients(1,:,3) = cpsCoefficients(q_0(3), q_1(3), q_dot_0(3), q_dot_1(3), t0, t_1);
% Segment 2: 2 < t < 4
coefficients(2,:,1) = cpsCoefficients(q_1(1), q_2(1), q_dot_1(1), q_dot_2(1), t_1, t_2);
coefficients(2,:,2) = cpsCoefficients(q_1(2), q_2(2), q_dot_1(2), q_dot_2(2), t_1, t_2);
coefficients(2,:,3) = cpsCoefficients(q_1(3), q_2(3), q_dot_1(3), q_dot_2(3), t_1, t_2);
% Create equations from coefficients
eqn(1,1) = vpa(poly2sym(fliplr(coefficients(1,:,1)),t));
eqn(2,1) = subs(vpa(poly2sym(fliplr(coefficients(2,:,1)),t)),t,t-2);
eqn(3,1) = vpa(poly2sym(fliplr(coefficients(1,:,2)),t));
eqn(4,1) = subs(vpa(poly2sym(fliplr(coefficients(2,:,2)),t)),t,t-2);
eqn(5,1) = vpa(poly2sym(fliplr(coefficients(1,:,3)),t));
eqn(6,1) = subs(vpa(poly2sym(fliplr(coefficients(2,:,3)),t)),t,t-2);
time_1 = 0:0.1:2;
time_2 = 2:0.1:4;
figure(1);
%Joint 1
subplot(3,1,1);
h = piecewise((t>=0)&(t<=2),eqn(1),(t>=2)&(t<=4),eqn(2));
fplot(h,'Color','#0072BD');
hold on;
h = diff(h);
fplot(h,'--','Color','#D95319');
hold on;
h = diff(h);
fplot(h,'-.','Color','#77AC30');
legend({'Position','Velocity','Acceleration'})
hold off;
xlabel('Time (s)');
ylabel('Position (deg)');
title('Joint 1 - CPS');
% Joint 2
subplot(3,1,2);
h = piecewise((t>=0)&(t<=2),eqn(3),(t>=2)&(t<=4),eqn(4));
fplot(h,'Color','#0072BD');
hold on;
h = diff(h);
fplot(h,'--','Color','#D95319');
hold on;
h = diff(h);
fplot(h,'-.','Color','#77AC30');
legend({'Position','Velocity','Acceleration'})
hold off;
xlabel('Time (s)');
ylabel('Position (deg)');
title('Joint 2 - CPS');
% Joint 3
subplot(3,1,3);
h = piecewise((t>=0)&(t<=2),eqn(5),(t>=2)&(t<=4),eqn(6));
fplot(h,'Color','#0072BD');
hold on;
h = diff(h);
fplot(h,'--','Color','#D95319');
hold on;
h = diff(h);
fplot(h,'-.','Color','#77AC30');
legend({'Position','Velocity','Acceleration'})
hold off;
xlabel('Time (s)');
ylabel('Position (m)');
title('Joint 3 - CPS');
eqn = string(eqn); %For table display purposes
cpsTable = table(eqn(1:2), eqn(3:4), eqn(5:6),'RowNames',{'Segment 1','Segment 2'},'VariableNames',{'Joint 1','Joint 2','Joint 3'});
cpsTable = table(cpsTable,'VariableNames',{'CPS Segment Equations'});
disp(cpsTable);
function [coeffs] = cpsCoefficients(theta_0, theta_f, theta_dot_0, theta_dot_f, t_0, t_f)
%Calculates and returns the CPS coefficients
a0 = theta_0;
a1 = theta_dot_0;
a2 = (3*(theta_f-theta_0)-(2*theta_dot_0+theta_dot_f)*(t_f-t_0))/((t_f-t_0)^2);
a3 = (2*(theta_0-theta_f)+(theta_dot_0+theta_dot_f)*(t_f-t_0))/((t_f-t_0)^3);
coeffs = [a0 a1 a2 a3];
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
