How to re-load MatLab's feedforwardnet to Workspace?

1 次查看(过去 30 天)
I create a feed-forward neural network 100 times, each time with different input and target. The trained model is saved into "FFNN_trained_sum" each time.
FFNN_trained_sum = []
for iteration = 1:100;
FFNN = feedforwardnet(20);
x = ...; t = ...; % assign the input "x" and target "t" with different datasets.
FFNN_trained = train(FFNN,x,t);
FFNN_trained_sum = [FFNN_trained_sum, FFNN_trained]
end
So after 100 times, the "FFNN_trained_sum" is a 1x100 network. How can I load the 37th network into MatLab Workspace? I tried the below but got error.
>> FFNN_trained_sum(37)
Scalar structure required for this assignment.
Error in network/sim (line 141)
net.trainFcn = ''; % Disable training related setup
Error in network/subsref (line 15)
otherwise, v = sim(vin,subs{:});

采纳的回答

Jon Cherrie
Jon Cherrie 2021-4-26
I recommend using a cell array rather than a regular array for this case, e.g.,
FFNN_trained_sum = {}; % Use {} here, not []
for iteration = 1:100;
FFNN = feedforwardnet(20);
x = ...;
t = ...;
FFNN_trained = train(FFNN,x,t);
FFNN_trained_sum{end+1} = FFNN_trained; % append the new network at the end
end
You can then access the 37th network via FFNN_trained_sum{37}
  2 个评论
Cheng Zhang
Cheng Zhang 2021-4-26
Sure, is there a way to convert the regular array to a cell array?
Jon Cherrie
Jon Cherrie 2021-4-26
If you already have that array of networks, and want the 37th one, you could try this:
s = struct(FFNN_trained_sum);
FFNN_trained_37 = network(s(37));
To convert the array to a cell array, this seems to work:
cellOfNetworks = {};
s = struct(FFNN_trained_sum);
for i = 1:length(s)
cellOfNetworks{end+1} = network(s(i));
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by