How can i combine 5 curves in one figure?

2 views (last 30 days)
Hello!
I have 5 figures, I want to combine the curves in such a way that only one curve can be seen .
this is the code
Xu=linspace(0,12,60);
Yu=linspace(0,10,60);
figure()
p1=plot(Xu,Yu)
xlabel('temps(min)')
ylabel('X(km)')
p1.LineWidth = 1.5;
grid on
%----------
Xu=linspace(12,24,60);
Yu=linspace(10,0,60);
figure()
p1=plot(Xu,Yu)
xlabel('temps(min)')
ylabel('X(km)')
p1.LineWidth = 1.5;
grid on
%-------------------
Xu=linspace(24,36,60);
Yu=linspace(0,10,60);
figure()
p1=plot(Xu,Yu)
xlabel('temps(min)')
ylabel('X(km)')
p1.LineWidth = 1.5;
grid on
%----------------
Xu=linspace(36,48,60);
Yu=linspace(10,0,60);
figure()
p1=plot(Xu,Yu)
xlabel('temps(min)')
ylabel('X(km)')
p1.LineWidth = 1.5;
grid on
%-------------
Xu=linspace(48,60,60);
Yu=linspace(0,10,60);
figure()
p1=plot(Xu,Yu)
xlabel('temps(min)')
ylabel('X(km)')
p1.LineWidth = 1.5;
grid on

Accepted Answer

Sam Chak
Sam Chak on 6 Sep 2022
Hi @Maria,
I didn't clean up the code. But more or less, the hold is used. You can also set the LineColor so that it appears as a piecewise function.
Xu=linspace(0,12,60);
Yu=linspace(0,10,60);
plot(Xu,Yu, 'LineWidth', 1.5), hold on
% xlabel('temps(min)')
% ylabel('X(km)')
% p1.LineWidth = 1.5;
% grid on
%----------
Xu=linspace(12,24,60);
Yu=linspace(10,0,60);
plot(Xu,Yu, 'LineWidth', 1.5), hold on
% xlabel('temps(min)')
% ylabel('X(km)')
% p1.LineWidth = 1.5;
% grid on
%-------------------
Xu=linspace(24,36,60);
Yu=linspace(0,10,60);
plot(Xu,Yu, 'LineWidth', 1.5), hold on
% xlabel('temps(min)')
% ylabel('X(km)')
% p1.LineWidth = 1.5;
% grid on
%----------------
Xu=linspace(36,48,60);
Yu=linspace(10,0,60);
plot(Xu,Yu, 'LineWidth', 1.5), hold on
% xlabel('temps(min)')
% ylabel('X(km)')
% p1.LineWidth = 1.5;
% grid on
%-------------
Xu=linspace(48,60,60);
Yu=linspace(0,10,60);
plot(Xu,Yu, 'LineWidth', 1.5), hold off
xlabel('temps(min)')
ylabel('X(km)')
grid on

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!