필터 지우기
필터 지우기

Time in While and Intergrator

조회 수: 2 (최근 30일)
Yamen Madamani
Yamen Madamani 2020년 8월 3일
댓글: Yamen Madamani 2020년 8월 13일
Hello ,
I have a problem . I want to calculate the time in m / s from While loop so that I can integrate the values. I tried a lot, unfortunately that didn't work. I use the MPU6050 accelerometer . Can you help please, best regards
delete(instrfindall);
clear all
clc
serialPort = 'COM2';
s=serial(serialPort,'BaudRate',9600);
fopen(s);
%tic
%t=0.004
m=[];
%t0=0
vec_ax=[0];
vec_ay=[0];
vec_az=[0];
while 1
%t_start=datetime('now')
x = fscanf(s);
m = str2num(x);
if isempty(m); continue; end
ax = m(1);
ay = m(2);
az = m(3);
%t_end=
%t_delta=
%vec_ax=[vec_ax, ax]
%vec_ay=[vec_ay, ay];
%vec_az=[vec_az, az];
%vec_t=[vec_t, t_delta]
%vx = cumtrapz(vec_ax, vec_t)
%vy = cumtrapz(vec_ay, vec_t)
%vz = cumtrapz(vec_az, vec_t)
end
fclose(s);

채택된 답변

Gaurav Garg
Gaurav Garg 2020년 8월 13일
Do you want the system time?
You can take use of clock function or
fprintf('The time is %s\n', datestr(now,'HH:MM:SS.FFF')).'
Or, if you wish to check the execution time, you can use tic-toc.
  댓글 수: 1
Yamen Madamani
Yamen Madamani 2020년 8월 13일
thank you i used tic toc

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by