How do I extract a ann's resulting function?

3 views (last 30 days)
Artur Boschi
Artur Boschi on 13 Jul 2011
Answered: TED MOSBY on 9 Jun 2025
Hi. I have an ANN with 4 inputs, 10 neurons and 1 output. It's already trained and I would like to "extract" the resulting function. I don't want to use the command sim every time I need the results that the net would give me. Is there a way to do that?
Thanks!

Answers (1)

TED MOSBY
TED MOSBY on 9 Jun 2025
Hi,
The Neural Network Toolbox includes "genFunction", which spits out an M-file you can call just like any other function:
% Suppose your trained network is called 'net' in your workspace:
genFunction(net, 'myNetFcn');
% This creates myNetFcn.m, containing something like:
% function y = myNetFcn(x)
% % AUTOGENERATED by Neural Network Toolbox
% .......
Then you can simple do:
y = myNetFcn(x); % x is your 4×N input matrix, y is 1×N output
Here is the documentation on "genfunction":
Hope this helps!

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!