Solving multiple related variables using if statement

조회 수: 3 (최근 30일)
asad ali
asad ali 2019년 6월 27일
답변: Guillaume 2019년 6월 27일
hi everyone
i have 3 variables (Temp, Voltage, Battery) that i want to correlate
what i want is that i get errors in temp variable using limits of all the three variables
limits are
when Temp<44 or Temp>56 with Volatge between 9.8 to 13.5 and battery 1 i should get errors of my variable Temp if it is <44 or if it is >56
battery limits are 1 or 0 (ON or OFF)
kindly help me
  댓글 수: 6
asad ali
asad ali 2019년 6월 27일
i am really sorry if i offend u
i dont have the code but i m going to attach my excel file n i need code for that with the limits that i told before
Bob Thompson
Bob Thompson 2019년 6월 27일
We aren't offended, just trying to explain that we can't help you if we don't know what you need help with.
'i need code for that with the limits that i told before'
This is very different than what you asked us before. How were you getting errors before if you didn't have any code?
I do not have the ability to access your excel file (its is a limitation on my end), nor do I have time to write a full code for you. The logic indexing that I wrote before is still the biggest part of the 'calculations' you're looking to do. The only other thing you would need to do first is read in your file, either with xlsread, or readtable.

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

채택된 답변

Guillaume
Guillaume 2019년 6월 27일
Nobody was offended, we're just trying to understand what you want as a result, which you haven't clearly explained. As said, coding the test is trivial but we don't know what to do with the result. You still haven't told us what you want as an output. I want errors doesn't mean anything.
So I'm going to take a guess as to the desired output. If that's not what you want, then please explain.
In matlab, using if and loops should be a last resort. There are usually much simpler ways of obtaining the result you want, as is the case here:
batterytest = readtable('Test.xlsx'); %import the data in a table
batterytest.isError = batterytest.Temp < 44 | batterytest.Temp > 56 %create new table variable which is true when temperature outside [44, 56]
You can trivially add more conditions to the isError test. eg.
batterytest.isError = batterytest.Temp < 44 | batterytest.Temp > 56 | batterytest.Voltage < 9.8 | batterytest.Voltage > 13.5 | batterytest.Battery == 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by