- https://www.mathworks.com/help/matlab/ref/tic.html
- https://www.mathworks.com/help/matlab/ref/toc.html
1개의 초음파센서 동작 속도 측정 방법?
2 views (last 30 days)
Show older comments
function y = fcn(u)
if u >=0.5
y=1;
else
y=0;
end;
인 함수 블록에 입력되는
초음파센서가 입력된 함수의 출력=1 에서 출력=0이 될때까지의 시간을 측정할 수 있는 방법이 있나요?
0 Comments
Answers (1)
Shivani
on 21 May 2024
Based on my understanding, you are looking to clock the total time taken for the output of the function fcn() ,’y’, to change from 1 to 0. I am assuming that there is an external function that is capturing the data from the ultrasonic sensor and storing it in the input variable ‘u’. Since the code calling the function 'fcn()' is not shared in the question, I am assuming that the function is being called within a loop with unique ‘u’ values at every iteration.
To calculate the total time taken for variable ‘y’ to move from 1 to 0, we can use the ‘tic’ and ‘toc’ function. Refer to the sample code attached below for an example of how to use these functions to determine the total execution time. Please note that I am assuming ‘u’ to be populated by the function ‘readUltrasonicSensor()’.
prev_y = fcn(readUltrasonicSensor());
startTime = tic;
while true
u = readUltrasonicSensor();
y = fcn(u);
if prev_y == 1 && y == 0
elapsedTime = toc(startTime); % Measure time since start
fprintf('Time elapsed from start to output change (1 to 0): %f seconds\n', elapsedTime);
break;
end
prev_y = y;
pause(0.01);
end
Additionally, you can refer to the following documentation link for more information:
Hope this helps!
0 Comments
See Also
Categories
Find more on 블록 라이브러리 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!