loop that checks conditions and counts the results

3 次查看(过去 30 天)
I have a question about a loop and how i can write it. I have created a random generator that gives numbers for four variables: x, y, z, s.
x is the floor number
y is the no of floor that is on fire
z is the detection of fire (either detect or not)
s is the extinguishing of fire ( either extinguish or not) it is also associated with each floor
now i want to create a loop that checks for the following 4 states and counts how many times they were satisfied.
1st state, x<y and count it
2nd state, for x>y check if z=0 (not detected) and count it else go to 3rdstate
3rd state, for x>y check if z=1 and s=0(not extinguished) and count it else go to 4th state
4th state, for x>y check if z=1 and s=1(detected) and count it

回答(1 个)

Adam Danz
Adam Danz 2021-3-30
编辑:Adam Danz 2021-3-31
I get the gist of the question but don't understand the details listed at the end of the question. Here's how to count conditions. You can adapt it to your needs. If you have any follow-up questions or want to add some details, let us know.
n = sum(x>y & z==1)
This requires the x,y,z vectors to all have the same number of elements.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by