How can i combine 5 curves in one figure?

조회 수: 4 (최근 30일)
Maria
Maria 2022년 9월 6일
댓글: Maria 2022년 9월 6일
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

채택된 답변

Sam Chak
Sam Chak 2022년 9월 6일
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
  댓글 수: 1
Maria
Maria 2022년 9월 6일
@Sam Chak this is what i want, thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by