Matlab子图循环:仅显示最后一次迭代中的图

时间:2019-08-12 09:28:09

标签: matlab matlab-figure

我试图通过在循环中添加子图来在Matlab中创建一个大图。

% Generation of examples and targets
x = 0 : 0.05 : 3 * pi;
y = sin(x.^2);

% Deep Learning Toolbox™ software arranges concurrent vectors with a
% matrix, and sequential vectors with a cell array (where the second index is the time step).
% con2seq and seq2con allow concurrent vectors to be converted to sequential vectors, and back again.

p = con2seq(x);
t = con2seq(y); % convert the data to a useful format

% Creation of networks (based on algorlm1.m)
num_hid = 50;

% Epoch quantities to evaluate
num_epochs = [1 20 1000]

% We'll evaluate these algorithms
training_algorithms = {
    'traingd',
    'traingda',
    'traincgf',
    'traincgp',
    'trainlm',
    'trainbfg'
};

%% Initialization 

% Create arrays to store networks and training parameters
networks = cell(length(training_algorithms), 1);

durations = zeros(length(training_algorithms), 1);
slopes = cell(length(training_algorithms), 1);
intercepts = cell(length(training_algorithms), 1);
correlations = cell(length(training_algorithms), 1);

for tai = 1:length(training_algorithms)

   % Create new feedforwardnet 
   net = feedforwardnet(num_hid, training_algorithms{tai});

   % Set all networks weights and biases equal (to the first one created)
   if tai > 1
        net.IW{1,1} = networks{tai-1}.IW{1,1};
        net.LW{1,1} = networks{tai-1}.LW{1,1};
        net.b{1} = networks{tai-1}.b{1};
        net.b{2} = networks{tai-1}.b{2};
   end

   % Store network
   networks{tai} = net;

end

figure;
for tai = 1:6

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

   % Train network, and time training
   tic;
   net = 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
   [slopes{tai}, intercepts{tai}, correlations{tai}] = postreg(y_result, y);

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

   % Plot results
   subplot(2,6,tai);
   plot(x,y,'bx',x,y_result,'r'); % Plot the sine function and the output of the network
   %title('1 epoch');
   legend('target',training_algorithms{tai},'Location','north');
   subplot(2,6, tai+6);
   postregm(y_result, y); % perform a linear regression analysis and plot the result

end

我只能得到在上一次迭代中创建的图(当tai == 6时)。我尝试在循环前面添加“保持”,然后再次将其关闭。任何想法为什么会这样?

编辑:这是结果图:

enter image description here

EDIT2:我添加了代码,以便可以复制它。您将需要深度学习工具箱。

0 个答案:

没有答案
相关问题