首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >循环遍历子图和保持

循环遍历子图和保持
EN

Stack Overflow用户
提问于 2019-08-16 21:11:34
回答 1查看 140关注 0票数 0

我正在尝试创建一个图,并在每个子图上添加多个函数。然而,我得到的输出只显示了每次迭代的最终图。换句话说,所有的子图都填充了一些东西,但只填充了我‘添加’的最后一条曲线(或者至少我认为我添加了) --青色曲线。我尝试在许多不同的地方使用hold on,但都无济于事。有没有人看到问题出在哪里?

代码语言:javascript
复制
%% Training phase

% Setting for plots

figure;

for tai = 1:length(training_algorithms)

    % Create first subplot (and make sure we stay there)
    subplot(3,2,tai);

    % Plot the (sampled) sine function
    plot(x,y,'bx');
    hold on
    colors = ['r', 'm', 'c'];

    for nh = 1:length(num_hid)

        net = networks{tai, nh}; % Load network
        net.trainParam.showWindow = false; % Don't show graph

        % Train network, and time training
        tic;
        [net, tr] = train(net, p, t);
        durations(tai)=toc;

        % Simulate input on trained networks (and convert to double format)
        y_result = cell2mat(sim(net, p));

        % Evaluate result
        [slo, int, correlations{tai}] = postregm(y_result, y);

        % Add network to array
        networks{tai} = net;

        % Plot network approximation results
        plot(x,y_result,colors(nh))

        ylim([-3 3])
        title(training_algorithms{tai});

    end
    hold off
end
EN

回答 1

Stack Overflow用户

发布于 2019-08-17 09:42:07

看起来这个问题已经得到了回答,但同样值得注意的是,即使您将net.trainParam.showWindow属性设置为“false”,Matlab仍然可以创建一个新图形并使其处于活动状态,即使它仍然处于隐藏状态。然后,您在此之后执行的任何绘图都不会像您希望的那样堆叠,除非您再次激活原始绘图。

例如,如果您运行下面的代码(我去掉了所有特定的函数,但重新创建了影响),您将看到在结束时,有20个左右的图形打开,但只有1个可见。取消对底部线条的注释,以便创建您想要的那种堆叠的子图...希望这能有所帮助。

干杯。

代码语言:javascript
复制
% Training phase
% Setting for plots
f1=figure(1);

for i = 1:6
    % Create first subplot (and make sure we stay there)
    subplot(3,2,i);
    x=0:.1:2*pi;
    y=sin(x);
    % Plot the (sampled) sine function
    plot(x,y,'b');
    hold on
    colors = {'r', 'm', 'c'};
    for j=1:3
        f2=figure;
        set(f2,'Visible','off');
        y2=sin(x+j);
        % Plot network approximation results
%         figure(f1) % - uncommment me
        plot(x,y2,colors{j})
    end
    hold off
end

figHandles = findobj('Type', 'figure')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57525301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档