This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create and Train a Feedforward Neural Network

This example shows how to train a feedforward neural network to predict temperature.

    Note:   You must be logged in with a MathWorks Account that is licensed to use the Neural Network Toolbox to run this example.

Read Data from the Weather Station ThingSpeak Channel

ThingSpeak™ channel 12397 contains data from the MathWorks® weather station, located in Natick, Massachusetts. The data is collected once every minute. Fields 2, 3, 4, and 6 contain wind speed (mph), relative humidity, temperature (F), and atmospheric pressure (hg) data respectively. Read the data from channel 12397 using the thingSpeakRead function.

data = thingSpeakRead(12397,'Fields',[2 3 4 6],'DateRange',[datetime('Sep 7, 2016'),datetime('Sep 9, 2016')],...

% Assign input variables
inputs = [data.Humidity'; data.TemperatureF'; data.PressureHg'; data.WindSpeedmph']; 
% Calculate dew point from temperature and relative humidity to use as the target
% Convert temperature from Fahrenheit to Celsius
tempC = (5/9)*(data.TemperatureF-32);
% Specify the constants for water vapor (b) and barometric pressure (c)
b = 17.62;
c = 243.5;
% Calculate the intermediate value 'gamma'
gamma = log(data.Humidity/100) + b*tempC ./ (c+tempC);
% Calculate dew point in Celsius
dewPointC = c*gamma ./ (b-gamma);
% Convert to dew point in Fahrenheit
dewPointF = (dewPointC*1.8) + 32;

% Assign target values for the network
targets = dewPointF';

Create Two-layer Feedforward Network

Use the feedforwardnet function to create a two-layer feedforward network. The network has one hidden layer with ten neurons and an output layer.

net = feedforwardnet(10);

Train the Feedforward Network

Use the train function to train the feed-forward network.

[net,tr] = train(net,inputs,targets);

Use the Trained Model to Predict Data

After the network is trained and validated, you can use the network object to calculate the network response to any input.

output = net(inputs(:,5))
output =


See Also


Was this topic helpful?