| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Neural Network Toolbox |
| Contents | Index |
Introduction to the GUI
The graphical user interface (GUI) is designed to be simple and user friendly. A simple example will get you started.
You bring up a GUI Network/Data Manager window. This window has its own work area, separate from the more familiar command-line workspace. Thus, when using the GUI, you might export the GUI results to the (command-line) workspace. Similarly, you might want to import results from the workspace to the GUI.
Once the Network/Data Manager window is up and running, you can create a network, view it, train it, simulate it, and export the final results to the workspace. Similarly, you can import data from the workspace for use in the GUI.
The following example deals with a perceptron network. It goes through all the steps of creating a network and shows what you might expect to see as you go along.
Create a Perceptron Network (nntool)
Create a perceptron network to perform the AND function in this example. It has an input vector p= [0 0 1 1;0 1 0 1] and a target vector t=[0 0 0 1]. Call the network ANDNet. Once created, the network will be trained. You can then save the network, its output, etc., by exporting it to the workspace.
Input and Target
To start, type nntool. The following window appears.
Click Help to get started on a new problem and to see descriptions of the buttons and lists.
First, define the network input, called p, having the value [0 0 1 1;0 1 0 1]. Thus, the network has a two-element input, and four sets of such two-element vectors are presented to it in training. To define this data, click New, and a new window, Create Network or Data, appears. Select the Data tab. Set the Name to p, the Value to [0 0 1 1;0 1 0 1], and make sure that Data Type is set to Inputs.
Click Create and then click OK to create an input p. The Network/Data Manager window appears, and p shows as an input.
Next create a network target. This time enter the variable name t, specify the value [0 0 0 1], and click Targets under Data Type. Again click Create and OK. You will see in the resulting Network/Data Manager window that you now have t as a target as well as the previous p as an input.
Create a Network
Now create a new network and call it ANDNet. Select the Network tab. Enter ANDNet under Name. Set the Network Type to Perceptron, for that is the kind of network you want to create.
You can set the inputs to p, and the example targets to t.
You can use a hardlim transfer function with the output range [0, 1] that matches the target values and a learnp learning function. For the Transfer function, select hardlim. For the Learning function, select learnp. The Create Network or Data window now looks like the following figure.
To examine the network, click View.
The View of New Network shows that you are about to create a network with a single input (composed of two elements), a hardlim transfer function, and a single output. This is the desired perceptron network.
Now click Create and OK to generate the network. Now close the Create Network or Data window. You see the Network/Data Manager window with ANDNet listed as a network.
Train the Perceptron
To train the network, click ANDNet to highlight it. Then click Open. This leads to a new window, labeled Network: ANDNet. At this point you can see the network again by clicking the View tab. You can also check on the initialization by clicking the Initialize tab. Now click the Train tab. Specify the inputs and output by clicking the Training Info tab and selecting p from the list of inputs and t from the list of targets. The Network: ANDNet window should look like
Note that the contents of the Training Results Outputs and Errors fields have the name ANDNet_ prefixed to them. This makes them easy to identify later when they are exported to the workspace.
While you are here, click the Training Parameters tab. It shows you parameters such as the epochs and error goal. You can change these parameters at this point if you want.
Click Train Network to train the perceptron network. The following training results appear.
The network was trained to zero error in five epochs. (Other kinds of networks commonly do not train to zero error, and their errors can cover a much larger range. On that account, their errors are plotted on a log scale rather than on a linear scale such as that used above for perceptrons.)
Confirm that the trained network does indeed give zero error by using the input p and simulating the network. To do this, go to the Network: ANDNet window and click the Simulate tab. Use the Inputs menu to specify p as the input, and label the output as ANDNet_outputsSim to distinguish it from the training output. Click Simulate Network in the lower right corner and click OK. In the Network/Data Manager you see a new variable in the output: ANDNet_outputsSim. Double-click it and a small window, Data: ANDNet_outputsSim, appears with the value
Thus, the network does perform the AND of the inputs, giving a 1 as an output only in this last case, when both inputs are 1. Close this window by clicking OK.
Export Perceptron Results to the Workspace
To export the network outputs and errors to the MATLAB® workspace, go back to the Network/Data Manager window. The output and error for ANDNet are listed in the Outputs and Errors fields on the right side. Next click Export. This gives you an Export from Network/Data Manager window. Click ANDNet_outputs and ANDNet_errors to highlight them, and then click the Export button.
These two variables now should be in the MATLAB workspace. To confirm this, go to the command line and type who to see all the defined variables. The result should be
You might type ANDNet_outputs and ANDNet_errors to obtain the following:
You can export p, t, and ANDNet in a similar way. You might do this and check using who to make sure that they got to the workspace.
Now that ANDNet has been exported, you can view the network description and examine the network weight matrix.
Your network might yield a different result.
Clear the Network/Data Window
You can clear the Network/Data Manager window by highlighting a variable such as p and clicking the Delete button until all entries in the list boxes are gone. By doing this, you start from a clean slate.
Alternatively, you can quit MATLAB. A restart with a new MATLAB, followed by nntool, gives a clean Network/Data Manager window.
Recall however, that you exported p, t, etc., to the workspace from the perceptron example. They are still there for your use even after you clear the Network/Data Manager window.
Importing from the Command Line
To make things simple, quit MATLAB. Start it again, and type nntool to begin a new session.
Click Import and set the destination Name to r (to distinguish between the variable named at the command line and the variable in the GUI). You will have a window that looks like this:
Click Import and verify by looking at the Network/Data Manager window that the variable r is there as an input.
Save a Variable to a File and Load It Later
Bring up the Network/Data Manager window and click New Network. Set the name to mynet. Click Create. The network name mynet should appear in the Network/Data Manager window. In this same window click Export. Select mynet in the variable list of the Export or Save window and click Save. This leads to the Save to a MAT File window. Save to the file mynetfile.
Now get rid of mynet in the GUI and retrieve it from the saved file. Go to the Network/ Data Manager window, highlight mynet, and click Delete. Click Import. This brings up the Import or Load to Network/Data Manager window. Click the Load from Disk button and type mynetfile as the MAT-file Name. Now click Browse. This brings up the Select MAT File window, with mynetfile as an option that you can select as a variable to be imported. Highlight mynetfile, click Open, and you return to the Import or Load to Network/Data Manager window. On the Import As list, select Network. Highlight mynet and click Load to bring mynet to the GUI. Now mynet is back in the GUI Network/Data Manager window.
| Provide feedback about this page |
![]() | Limitations and Cautions | Linear Filters | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |