MATLAB: Matlab and thingspeak manipulate data before plotting

iotreplace numberThingSpeak

Hi, first of all I wish to specify I'm a complete noob with matlab. I'm using thingspeak to plot data send by a sensor. Basic thingspeak vialisation doesn't do what I wish so I'm looking for an easy solution to my problem without spending tons of hours to learn how this works. I already tried some stuffs but I just can't figure out how to modify to fit my needs. here my TS channe: https://thingspeak.com/channels/470434 1-the sensor print -299 value for an error in measurements, I wish to ignore theses points for the line created(so it doesn't bump down every time). But it could be interesting to be able to see the -299 value somewhere so I can figure out when the sensor did a wrong measurement. 2-Also I would be able to give -275 to all values between -275 and -298.
thanks in advance

Best Answer

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.