matlab and thingspeak manipulate data before plotting

조회 수: 2 (최근 30일)
Simon Béland
Simon Béland 2018년 10월 2일
댓글: Christopher Stapels 2018년 10월 5일
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

채택된 답변

Christopher Stapels
Christopher Stapels 2018년 10월 3일
편집: Christopher Stapels 2018년 10월 5일
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.
  댓글 수: 2
Simon Béland
Simon Béland 2018년 10월 4일
Ok thanks for your reply. I tried this but get an error. just some questions about this: 1- on which channel should I create the analysis? 2-I get an error on this: 21th line= thingSpeakWrite(594ThisIsMyNewChannel393,'Fields',[1,2],'Values',[value,f2Value],'WriteKey','J7xxxxxxxxx9');
Error using writeonanotherchannelfiltered (line 21) Error using thingSpeakWrite 'Values' must be a scalar, a 1-by-n numeric vector, or a cell array and must have the same dimensions as the 'Fields' value.
3-on which channel do I create the react?
thanks
Christopher Stapels
Christopher Stapels 2018년 10월 5일
1. MATLAB Analyses can be created independent of the channel. I really recommend you go through the getting started tutorial, just to get a handle on things: https://www.mathworks.com/help/thingspeak/getting-started-with-thingspeak.html Its pretty quick.
2. I edited the post above. Forgot to convert the string read from ThingSpeak to a number. value=str2num(webread('http://api.thingspeak.com/channels/470434/fields/1/last'));
3. I would set up the react on the channel that contains the data that you want to react to, probably the raw data channel.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 ThingSpeak에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by