How to re-load MatLab's feedforwardnet to Workspace?
1 view (last 30 days)
Show older comments
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{:});
0 Comments
Accepted Answer
Jon Cherrie
on 26 Apr 2021
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 Comments
Jon Cherrie
on 26 Apr 2021
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
More Answers (0)
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!