Using inequalities to compare arrays

조회 수: 3 (최근 30일)
Wyatt Jankauskas
Wyatt Jankauskas 2019년 2월 21일
댓글: Wyatt Jankauskas 2019년 2월 22일
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일
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월 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개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by