gpt4 book ai didi

matlab - 1 个循环中的多个图形,每次迭代在每个图形上添加一条线

转载 作者:太空宇宙 更新时间:2023-11-03 20:00:39 27 4
gpt4 key购买 nike

尝试在 Matlab 中设计以下内容:

** loop start;
y(:,i) = function of x;
z(:,i) = function of x;
plot(x,y(:,i)) on figure 1, hold all;
plot(x,z(:,i)) on figure 2, hold all;
** loop end;
add title, legend, etc for figure 1 (NB: we have multiple lines);
add title, legend, ets for figure 2 (NB: same, have multiple lines for the legend);`

尝试了多种组合,但运气不佳。设法得到 2 个数字,但只有第 2 个数字显示多行,而不是第一个。并且不知道如何正确地为这两个添加图例。

最佳答案

保存每个图形和每个轴对象的句柄:

fh1 = figure;
hold all;
ah1 = gca;

fh2 = figure;
hold all;
ah2 = gca;

for i=1:N
y(:,i) = function of x;
z(:,i) = function of x;
plot(ah1, x, y(:,i)); %# tell it which axis to use (ah1)
plot(ah2, x, z(:,i)); %# (ah2)
end

legend(ah1, ...) %# legend options here
legend(ah2, ...) %# and the other legend

%# note: you can set figure properties for each using fh1, fh2 handles.

关于matlab - 1 个循环中的多个图形,每次迭代在每个图形上添加一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12134406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com