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