在Matlab中为图形添加参数
add parameters to the figure in Matlab
我在 Matlab 中有一个绘图如下,我想向图中添加一些参数,就像我添加的图一样。你能帮我解决这个问题吗?非常感谢。
delta = 0.5;
I1=2;
I2 =4;
T = 5;
tau = 0.5;
b = 8;
a = 6;
c = 8;
d = 4;
t = [0:0.001:5];
y =(a-b*exp(-tau*t)).*(t>=0 & t<delta*T )+(-d+c*exp(-tau*(t-delta*T))).*(t>=delta*T & t<=T);
plot(t,y , 'b', 'LineWidth',1.8)
hold on
x = [0:0.01:12];
max = 4*ones(1,1201);
min = -2*ones(1,1201);
z = 0*ones(1,1201);
plot(x,max , '--g', 'LineWidth',1)
hold on
plot(x,min , '--g', 'LineWidth',1)
plot(2,min , '--g', 'LineWidth',1)
plot(x,z , 'k', 'LineWidth',1.7)
axis([0 6 -4 6])
我认为这段代码可能会生成与您正在查找的内容相近的内容。重要的是要说 x 和 y 的箭头可以使用相同的“注释命令”添加。
delta = 0.5;
I1=2;
I2 =4;
T = 5;
tau = 0.5;
b = 8;
a = 6;
c = 8;
d = 4;
t = [0:0.001:5];
y =(a-b*exp(-tau*t)).*(t>=0 & t<delta*T )+(-d+c*exp(-tau*(t-delta*T))).*(t>=delta*T & t<=T);
plot(t,y , 'b', 'LineWidth',1.8,'DisplayName',"Data")
% Change the y limits
ylim([-4 6])
hold on
% %% Set the horizontal lines and its name in the y axis
% MAX LINE - Create a yline Cte along the plot
hLine = yline(4);
hLine.LineWidth = 1;
hLine.Color = "g";
hLine.LineStyle = "--";
hLine.DisplayName = "Max Line";
% MIN LINE - Create a yline Cte along the plot
hLine = yline(-2);
hLine.LineWidth = 1;
hLine.Color = "g";
hLine.LineStyle = "--";
hLine.DisplayName = "Min Line";
% Zero LINE - Create a yline Cte along the plot
hLine = yline(0);
hLine.LineWidth = 1.7;
hLine.Color = "k";
hLine.LineStyle = "-";
% Change the "name" in the y axis
hAxis = gca;
% Get index
% - when y is equal to "Max" in this case 4
% - when y is equal to "MIN" in this case -2
idx = hAxis.YTick == 4;
hAxis.YTickLabel{idx} = 'X';
idx = hAxis.YTick == -2;
hAxis.YTickLabel{idx} = 'Y';
% %% Set the vertical lines and its name in the x axis
% Delta LINE - Create a xline Cte along the plot
hLine = xline(2.5);
hLine.LineWidth = 1;
hLine.Color = "k";
hLine.LineStyle = "-";
% MIN LINE - Create a yline Cte along the plot
hLine = xline(4);
hLine.LineWidth = 1;
hLine.Color = "k";
hLine.LineStyle = "-";
% Add the notes
annotation('textbox',[.55 .2 .3 .3],"String","Delta",...
'FitBoxToText','on','LineStyle','none')
annotation('textbox',[0.8 0.2 .3 .3],"String","A",...
'FitBoxToText','on','LineStyle','none')
前面的代码会生成下一张图
我在 Matlab 中有一个绘图如下,我想向图中添加一些参数,就像我添加的图一样。你能帮我解决这个问题吗?非常感谢。
delta = 0.5;
I1=2;
I2 =4;
T = 5;
tau = 0.5;
b = 8;
a = 6;
c = 8;
d = 4;
t = [0:0.001:5];
y =(a-b*exp(-tau*t)).*(t>=0 & t<delta*T )+(-d+c*exp(-tau*(t-delta*T))).*(t>=delta*T & t<=T);
plot(t,y , 'b', 'LineWidth',1.8)
hold on
x = [0:0.01:12];
max = 4*ones(1,1201);
min = -2*ones(1,1201);
z = 0*ones(1,1201);
plot(x,max , '--g', 'LineWidth',1)
hold on
plot(x,min , '--g', 'LineWidth',1)
plot(2,min , '--g', 'LineWidth',1)
plot(x,z , 'k', 'LineWidth',1.7)
axis([0 6 -4 6])
我认为这段代码可能会生成与您正在查找的内容相近的内容。重要的是要说 x 和 y 的箭头可以使用相同的“注释命令”添加。
delta = 0.5;
I1=2;
I2 =4;
T = 5;
tau = 0.5;
b = 8;
a = 6;
c = 8;
d = 4;
t = [0:0.001:5];
y =(a-b*exp(-tau*t)).*(t>=0 & t<delta*T )+(-d+c*exp(-tau*(t-delta*T))).*(t>=delta*T & t<=T);
plot(t,y , 'b', 'LineWidth',1.8,'DisplayName',"Data")
% Change the y limits
ylim([-4 6])
hold on
% %% Set the horizontal lines and its name in the y axis
% MAX LINE - Create a yline Cte along the plot
hLine = yline(4);
hLine.LineWidth = 1;
hLine.Color = "g";
hLine.LineStyle = "--";
hLine.DisplayName = "Max Line";
% MIN LINE - Create a yline Cte along the plot
hLine = yline(-2);
hLine.LineWidth = 1;
hLine.Color = "g";
hLine.LineStyle = "--";
hLine.DisplayName = "Min Line";
% Zero LINE - Create a yline Cte along the plot
hLine = yline(0);
hLine.LineWidth = 1.7;
hLine.Color = "k";
hLine.LineStyle = "-";
% Change the "name" in the y axis
hAxis = gca;
% Get index
% - when y is equal to "Max" in this case 4
% - when y is equal to "MIN" in this case -2
idx = hAxis.YTick == 4;
hAxis.YTickLabel{idx} = 'X';
idx = hAxis.YTick == -2;
hAxis.YTickLabel{idx} = 'Y';
% %% Set the vertical lines and its name in the x axis
% Delta LINE - Create a xline Cte along the plot
hLine = xline(2.5);
hLine.LineWidth = 1;
hLine.Color = "k";
hLine.LineStyle = "-";
% MIN LINE - Create a yline Cte along the plot
hLine = xline(4);
hLine.LineWidth = 1;
hLine.Color = "k";
hLine.LineStyle = "-";
% Add the notes
annotation('textbox',[.55 .2 .3 .3],"String","Delta",...
'FitBoxToText','on','LineStyle','none')
annotation('textbox',[0.8 0.2 .3 .3],"String","A",...
'FitBoxToText','on','LineStyle','none')
前面的代码会生成下一张图