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

조회 수: 1 (최근 30일)
Cheng Zhang
Cheng Zhang 2021년 4월 25일
댓글: Jon Cherrie 2021년 4월 26일
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by