Integral in matlab func
조회 수: 2 (최근 30일)
이전 댓글 표시
hey; I'm getting this error and don't understand why. hope someone can help...
Persistent variable 'time_k1' is undefined on some execution paths. Function 'MATLAB Function5' (#61.404.411), line 24, column 17: "time_k1" Launch diagnostic report.
here is my func:
function [theta,V,Vx,Vy] = meas(Acc,gyro,time)
persistent theta_k1 wz_k1 Vx_k1 Vy_k1 Ax_k1 Ay_k1 time_k1
wz = gyro(3);
Ax = Acc(1);
Ay = Acc(2);
if time<0.01
theta_k1 = 0;
wz_k1 = 0;
Vx_k1 = 0;
Vy_k1 = 0;
Ax_k1 = 0;
Ay_k1 = 0;
time_k1 = time;
theta = 0;
V = 0;
Vx = 0;
Vy = 0;
else
% Integration for theta:
dt = time - time_k1;
theta = theta_k1 + dt*(wz + wz_k1)/2;
% Integration for V:
Vx = Vx_k1 + dt*(Ax + Ax_k1)/2;
Vy = Vy_k1 + dt*(Ay + Ay_k1)/2;
V = sqrt(Vx^2+Vy^2);
% Store for next step:
theta_k1 = theta;
wz_k1 = wz;
Vx_k1 = Vx;
Vy_k1 = Vy;
Ax_k1 = Ax;
Ay_k1 = Ay;
end
댓글 수: 0
답변 (1개)
Torsten
2022년 7월 8일
편집: Torsten
2022년 7월 8일
You get this error because you didn't assign a value to the variable "time" when you called "meas" or a value >= 0.01.
If you give values to Acc, gyro and time (as I can see, Acc is an array of size at least 2 and gyro is an array of size at least 3) and then call "meas", you will have no problems.
댓글 수: 6
Torsten
2022년 7월 9일
편집: Torsten
2022년 7월 9일
Change the line
if time<0.01
to
if time == 0
and call the function "meas" with time = 0 and arbitrary data for "Acc" and "gyro" before sensor data are being transfered to "meas".
Further in the "else" part, I think you will have to add the line
time_k1 = time
to store it for the next step.
참고 항목
카테고리
Help Center 및 File Exchange에서 Setup and Configuration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!