I would recommend setting up a new channel. Then you can set a react to call a MATLAB analysis to write the data to the new channel. First create the new MATLAB analysis. I would read the last data point from the channel.
f2Value=NaN;
value=str2num(webread('http://api.thingspeak.com/channels/470434/fields/1/last'));
if and((value>-299),(value<-274))
value=-275
end
if (value==-299)
value=NaN;
f2Value=1;
end
%now write to the new channel
thingSpeakWrite(<newID>,'Fields',[1,2],'Values',[value,f2Value],'WriteKey','XXXXXXXXXXXXXXXX');
Be sure to change the channel ID and the write API key.
Now create a new react and set the react to act on data entry for your first field, and make the criteria such that it will always be called (I like to use if field 1 value is not equal to 'fish'). Then select MATLAB Analysis as the action and choose the name of the MATLAB analysis you created.
Field 2 will show the number of times you got bad data, and field 1 will have the values you wanted.
Best Answer