while a variable is true for a certain period of time
18 views (last 30 days)
Show older comments
hey, i am trying to make an if statement nested in a while loop by having a condition anded with a time period. if the condition is true for that period of time, do what ever is in the if statement. for example , let a variable called 'result'. when the user presses the button the while loop start calculations to get ' result'. what i want is, when the result value does not change for 25 second, another function will execute.
what i am really doing is calculating the delay between two microphones and with that calculating angle of the sound source, if the angle is 0, there are no sound. if there is no sound for 25 second,no one is speaking and the device is not being used, in that case i want to do some commands that will cut off power from devices attached to parallel port. i have done all needed codes but i dont know how to write an if statement that tells matlab do these lines of codes if the angle stays zero for 25 seconds.
any ideas ??
0 Comments
Answers (1)
Sara
on 27 Mar 2014
You could call the function
c = clock; where c is [year month day hour minute seconds]
before the loop and call it at every iteration to see if 25 s have passed. So
initTime = clock;
newTime = initTime
while condition && newTime(6)-initTime(6) < 25
...code
newTime = clock;
end
2 Comments
Sara
on 27 Mar 2014
I'd try debugging looking if maybe ang or T1 are strings or arrays...That's usually why you get that error. Can you share the code you wrote? Details matter.
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!