Fred
Fred

Reputation: 427

how to use a neural network with simulink and neural network toolbox

I am trying to use a neural network generated from neural network toolbox with simulink model.

The NN is a controller for a inverted pendulum. Whenever I build a net, it always generate a net with a single input. My problem needs to be solved with two input a one output, and after that, I have to put that net on a simulink block, but I can't find the correct tool. The only one I see requires two network model for I don't know why.

May anyone help me, please?

Upvotes: 1

Views: 6097

Answers (1)

Grittathh
Grittathh

Reputation: 56

Before you try to convert to a simulink block, you should make sure your trained NN works correctly in matlab. What do you mean there is a single input? All of the inputs should be in the same data structure (for example, a matrix) where the number of rows = the number of "inputs".

Here's an example using the house_dataset. You can get this example code just by typing "help house_dataset" at the matlab command line.

[x,t] = house_dataset;
net = fitnet(10);
net = train(net,x,t);
view(net)
y = net(x);

Anyway, x is a 13 by 506 vector. The trained network has an input of size 13:

net.inputs{1}.size

ans =

13

What do you see with your trained network? Do you give it a 2D input vector?

Once your network is trained and you have the right input size, you can transfer the network to simulink using the gensim function. Once in simulink, you can send inputs to the NN by building an input vector using something like a mux and wire this to the network as a single signal. Of course, you can generate vectors many ways, you don't have to use a mux.

Upvotes: 1

Related Questions