This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Find Mean of Data Ignoring NaN Values

This example shows how to find the mean of data in a ThingSpeak™ channel while ignoring the NaN values.

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 3 and 4 contain humidity and temperature data respectively. Read the data over the last day from channel 12397 using the thingSpeakRead function.

data = thingSpeakRead(12397,'NumDays',1,'Fields',[3 4],'outputFormat','matrix');

Find Mean Without NaN Values

The nanmean function returns a matrix of mean values that are computed after removing NaN values.

mean = nanmean(data)
mean =

   54.2651   39.8932

See Also