Solving multiple related variables using if statement
显示 更早的评论
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 个评论
Guillaume
2019-6-27
What does I should get errors actually mean in practice?
Bob Thompson
2019-6-27
编辑:Bob Thompson
2019-6-27
Please copy the entire error message for us to see.
I'm going to assume that all three of your variables are a single column vector with the same number of elements. If that assumption is correct then it is a bit easier to combine down to a single large logic index.
A = [Battery, Temp, Voltage];
B = A(A(:,1)==1 & (A(:,2)>56 | A(:,2)<44) & (A(:,3)>9.8 & A(:,3)<13.5),2);
Guillaume
2019-6-27
I am not asking for the condition for the error, you've already given us that. You haven't explained what I should get errors mean.
The standard meaning of I get an error is that your code aborts with a red display: Error on line xxx: error message which I assume is not what you want.
Does it mean that you want a message displayed (at the command window? in a GUI? somwhere else?) for each error value? It actually sounds like what you call I get an error is that the values are copied in another variable but it's not clear.
Detecting the errors is easy, Bob has already shown you how to do it (I'd use a table instead of a matrix, for clarity). What we don't know is what I should get errors actually mean.
asad ali
2019-6-27
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!