thingspeak 数据的带逻辑运算符的条件语句
conditional statement with logical operators for thingspeak data
我正在为我的气象站编写一个关于 matlab 分析的 thingspeak 代码,它检查最后 24 个读数,然后根据给定条件发出警报,我给出了这个条件,但我想我弄乱了一些东西因此得到错误的结果。我希望答案总体上是逻辑 1 或 0。即使是不应该给我 1 的值,我也得到 1,并且两个变量的答案都是 24*1 逻辑数组。但即便如此,也不会生成推文。这是我的代码;
t =thingSpeakRead(293182,'Fields',1,'NumPoints',24,'OutputFormat','matrix');
h =thingSpeakRead(293182,'Fields',2,'NumPoints',24,'OutputFormat','matrix');
DangerAlert = ((t>42.5)&(t<43.5)&(h>17)&(h<21))|(((t>40.5)&(t<43.5))&((h>21)&(h<27)))|((t>39.5)&(t<43.5)&(h>27)&(h<31)) | ((t>38.5)&(t<43.5)&(h>31)&(h<37))| ((t>37.5)&(t<42.5)&(h>37)&(h<41))| ((t>36.5)&(t<40.5)&(h>41)&(h<47))| ((t>35.5)&(t<39.5)&(h>47)&(h<51))| ((t>34.5)&(t<38.5)&(h>51)&(h<57))| ((t>33.5)&(t<38.5)&(h>57)&(h<68))| ((t>33.5)&(t<37.5)&(h>63)&(h<68)) | ((t>32.5)&(t<38.5)&(h>68)&(h<73)) | ((t>31.5)&(t<35.5)&(h>73)&(h<83))| ((t>30.5)&(t<33.5)&(h>83)&(h<88)) | ((t>29.5)&(t<33.5)&(h>83)&(h<93))| ((t>29.5)&(t<32.5)&(h>93)&(h<100))
HeatStrokeAlert=((t>42.5)&(t<43.5)&(h>37)&(h<41)) | ((t>40.5)&(t<2.5)&(h>41)&(h<47)) | ((t>39.5)&(t<41.5)&(h>47)|(h<51))| ((t>38.5)&(t<40.5)&(h>51)&(h<57))| ((t>38.5)&(t<39.5)&(h>57)&(h<63))| ((t>37.5)&(t<38.5)&(h>63)&(h<68))| ((t>36.5)&(t<38.5)&(h>68)&(h<78))| ((t>35.5)&(t<37.5)&(h>73)&(h<83)) | ((t>34.5)&(t<36.5)&(h>83)&(h<88)) | ((t>33.5)&(t<36.5)&(h>88)&(h<93)) | ((t>33.5)&(t<35.5)&(h>93)&(h<97)) | ((t>32.5)&(t<34.5)&(h>97))
if DangerAlert
webwrite('http://api.thingspeak.com/apps/thingtweet/1/statuses/update','api_key', 'XXXXXXXXXXXXX', 'status', 'Alert!Dangerously High temperature tomorrow!')
end
if HeatStrokeAlert
webwrite('http://api.thingspeak.com/apps/thingtweet/1/statuses/update','api_key', 'XXXXXXXXX', 'status', 'Alert!Heat Stroke alert tomorrow!')
end
我知道错误是minor.But这需要解决。
t 的范围值从 29.5 到 43.5,h 的范围值从 17 到 100。因此,您在这些数字之间输入的任何值都会得到 1,因为您使用的是 OR 语句 ||。因此,如果其中任何一个为真,它将返回真 (=1)。
此外,对于网站,请务必遵循以下说明:
https://www.mathworks.com/help/matlab/ref/webwrite.html
确保您拥有 ThinkSpeak 帐户,并尝试更改您的 URL 以匹配其格式:
[thingSpeakURL 'update'];
所以添加 'update' 字符串并使用括号。
此外,将您的 if 语句表达式设置为 1。所以:
如果 DangerAlert = 1
我正在为我的气象站编写一个关于 matlab 分析的 thingspeak 代码,它检查最后 24 个读数,然后根据给定条件发出警报,我给出了这个条件,但我想我弄乱了一些东西因此得到错误的结果。我希望答案总体上是逻辑 1 或 0。即使是不应该给我 1 的值,我也得到 1,并且两个变量的答案都是 24*1 逻辑数组。但即便如此,也不会生成推文。这是我的代码;
t =thingSpeakRead(293182,'Fields',1,'NumPoints',24,'OutputFormat','matrix');
h =thingSpeakRead(293182,'Fields',2,'NumPoints',24,'OutputFormat','matrix');
DangerAlert = ((t>42.5)&(t<43.5)&(h>17)&(h<21))|(((t>40.5)&(t<43.5))&((h>21)&(h<27)))|((t>39.5)&(t<43.5)&(h>27)&(h<31)) | ((t>38.5)&(t<43.5)&(h>31)&(h<37))| ((t>37.5)&(t<42.5)&(h>37)&(h<41))| ((t>36.5)&(t<40.5)&(h>41)&(h<47))| ((t>35.5)&(t<39.5)&(h>47)&(h<51))| ((t>34.5)&(t<38.5)&(h>51)&(h<57))| ((t>33.5)&(t<38.5)&(h>57)&(h<68))| ((t>33.5)&(t<37.5)&(h>63)&(h<68)) | ((t>32.5)&(t<38.5)&(h>68)&(h<73)) | ((t>31.5)&(t<35.5)&(h>73)&(h<83))| ((t>30.5)&(t<33.5)&(h>83)&(h<88)) | ((t>29.5)&(t<33.5)&(h>83)&(h<93))| ((t>29.5)&(t<32.5)&(h>93)&(h<100))
HeatStrokeAlert=((t>42.5)&(t<43.5)&(h>37)&(h<41)) | ((t>40.5)&(t<2.5)&(h>41)&(h<47)) | ((t>39.5)&(t<41.5)&(h>47)|(h<51))| ((t>38.5)&(t<40.5)&(h>51)&(h<57))| ((t>38.5)&(t<39.5)&(h>57)&(h<63))| ((t>37.5)&(t<38.5)&(h>63)&(h<68))| ((t>36.5)&(t<38.5)&(h>68)&(h<78))| ((t>35.5)&(t<37.5)&(h>73)&(h<83)) | ((t>34.5)&(t<36.5)&(h>83)&(h<88)) | ((t>33.5)&(t<36.5)&(h>88)&(h<93)) | ((t>33.5)&(t<35.5)&(h>93)&(h<97)) | ((t>32.5)&(t<34.5)&(h>97))
if DangerAlert
webwrite('http://api.thingspeak.com/apps/thingtweet/1/statuses/update','api_key', 'XXXXXXXXXXXXX', 'status', 'Alert!Dangerously High temperature tomorrow!')
end
if HeatStrokeAlert
webwrite('http://api.thingspeak.com/apps/thingtweet/1/statuses/update','api_key', 'XXXXXXXXX', 'status', 'Alert!Heat Stroke alert tomorrow!')
end
我知道错误是minor.But这需要解决。
t 的范围值从 29.5 到 43.5,h 的范围值从 17 到 100。因此,您在这些数字之间输入的任何值都会得到 1,因为您使用的是 OR 语句 ||。因此,如果其中任何一个为真,它将返回真 (=1)。
此外,对于网站,请务必遵循以下说明: https://www.mathworks.com/help/matlab/ref/webwrite.html
确保您拥有 ThinkSpeak 帐户,并尝试更改您的 URL 以匹配其格式: [thingSpeakURL 'update']; 所以添加 'update' 字符串并使用括号。
此外,将您的 if 语句表达式设置为 1。所以: 如果 DangerAlert = 1