Azzera filtri
Azzera filtri

How to remove dashed vertical line in graph

9 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 5 Nov 2021
Try this —
In the ‘Joint1’ plots —
h = diff(h);
hfp1 = fplot(h,'-.','Color','#77AC30');
hfp1.ShowPoles = 'off';
I made that change in the code.
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);
hfp1 = fplot(h,'-.','Color','#77AC30');
hfp1.ShowPoles = 'off';
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);
CPS Segment Equations Joint 1 Joint 2 Joint 3 _____________________________________________________________________________________________________________________________________________________ Segment 1 "4.5*t^3 - 11.0*t^2" "13.75*t^2 - 1.25*t^3" "0.05*t^2" Segment 2 "10.0*t - 71.5*(t - 2)^2 + 23.0*(t - 2)^3 - 28.0" "40.0*t - 6.25*(t - 2)^2 - 1.25*(t - 2)^3 - 35.0" "0.2*t - 0.05*(t - 2)^2 - 0.2"
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
.
  3 Commenti
Connor LeClaire
Connor LeClaire il 5 Nov 2021
To answer my own comment above: the vertical joining segment was not shown because the graph's y limits were too small and caused it to be cutoff. Adding a ylim([-150 150]) to the end of the joint 1 section resolved this.
Star Strider
Star Strider il 5 Nov 2021
It was likely never there to begin with, and the pole line was where it should have been plotted. It will probably be necessary to code it specifically and then plot it. The connecting lines in the other plot are there because there was no discontinuity (pole).
The other possibility is to remove the discontinuity in the code, since then that will likely plot that line continuously.
I defer to you for that, since the problem is not readily apparent in the extremely complex code.
.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by