How can i combine 5 curves in one figure?

2 ビュー (過去 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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by