Hello I am working on a code that will determine if data is within or beyond standard deviations of a particular curve. I currently cannot get to the point where I can alert a user via email because my if statement is comparing two arrays rather than two numbers.
%Define Variables
Time = table2array(SampleDataOutput(:,1));
Temp = table2array(SampleDataOutput(:,2));
CowA = table2array(CowADataOutput(:,2));
%Set Tolerances based on Sample
HighTolerance = Temp + std(Temp);
HighTolerance2 = Temp + (2*std(Temp));
LowTolerance = Temp - std(Temp);
LowTolerance2 = Temp - (2*std(Temp));
%Plot Cow A against Tolerances
figure(1)
plot(Time,Temp,'color','green')
hold on
plot(Time,HighTolerance,'color','yellow')
plot(Time,HighTolerance2,'color','red')
plot(Time,LowTolerance,'color','yellow')
plot(Time,LowTolerance2,'color','red')
plot(Time,CowA,'color','black')
hold off
title('Cow A from 5:30AM to 11:00AM')
xlabel('Time (15-minute increments)')
ylabel('Temperature (Degrees Fahrenheit)')
legend ('Green=Ideal', 'Yellow=Warning','Red=Sick Cow')
% If-Then Cow A - Alerts
if CowA > HighTolerance && CowA < HighTolerance2 % THIS IS NOT WORKING BECAUSE INEQUALITY FOR TWO ARRAYS
sendmail('example@gmail.com','Cow A Health-FRS', ...
'Cow A should be watched, please look at your updated site to see more details.');
end
if CowA > HighTolerance2
sendmail('example.com','Cow A Health-FRS', ...
'Cow A seems to have a fever based on our readings. Please see your updated site for more details asap!');
end

 採用された回答

Image Analyst
Image Analyst 2019 年 2 月 21 日

2 投票

What are the sizes (rows and columns) of CowA and HighTolerance2?
Do you want to enter the "if" if ALL of them are true, or if ANY of them are true?
Use all() or any() to compare arrays.

10 件のコメント

Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 21 日
both are 1 column and 23 rows.
I want to send an email when the CowA temp is higher then the tolerances and a separate message when it is inbetween the tolerances. As an example for CowA based on this picture the code should mark it as good because it is within these bounds, but for CowC i want it to send a notification via email. Does this make sense?
Cow C.jpg
Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 21 日
Cow A.jpg
Image Analyst
Image Analyst 2019 年 2 月 21 日
No it doesn't make sense (to me). Those are two vectors, and some elements are between the tolerances and some are not. So in that case, do you want to send an email or not? Surely you don't want to send an email for every element of the vector that is in between the tolerances. You probably don't want to send dozens of emails. You probably only want to send one, unless you're capturing data over a long time, like hours, and want to send one every time based on the latest measurement rather than the whole vector.
Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 22 日
Okay i see what you mean. is there a way that i can say
“if 5 points are beyond hightolerance send mail”?
Image Analyst
Image Analyst 2019 年 2 月 22 日
Yes:
mask = CowA > HighTolerance & CowA < HighTolerance2; % Use single & NOT double &&
if sum(mask) > 5
% Send mail if more than 5 elements are in the tolerance range.
sendmail(............)
end
Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 22 日
Alright, I think I am in the right direction! Do you know why it would be telling me that when saying:
mask = CowA > HighTolerance & CowA < HighTolerance2;
That the & might not be used? That is the only thing giving me an error now
Image Analyst
Image Analyst 2019 年 2 月 22 日
If CowA is a vector, and HighTolerance and HighTolerance2 are scalars, or vectors the same size and shape as CowA, it should work. What does this show:
whos CowA
whos HighTolerance
whos HighTolerance2
Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 22 日
Name Size Bytes Class Attributes
CowA 23x1 184 double
Name Size Bytes Class Attributes
HighTolerance 23x1 184 double
Name Size Bytes Class Attributes
HighTolerance2 23x1 184 double
Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 22 日
Undefined function or variable 'mask'.
Error in frs3 (line 116)
mask == CowA >= HighTolerance & CowA <= HighTolerance2;
Wyatt Jankauskas
Wyatt Jankauskas 2019 年 2 月 22 日
Oops I took out the double == and it works! Thanks so much!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by