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

1 visualizzazione (ultimi 30 giorni)
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]
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{:});

Risposta accettata

Jon Cherrie
Jon Cherrie il 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
You can then access the 37th network via FFNN_trained_sum{37}
  2 Commenti
Jon Cherrie
Jon Cherrie il 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));

Accedi per commentare.

Più risposte (0)


Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by