Integral in matlab func

2 visualizzazioni (ultimi 30 giorni)
Dekel Mashiach
Dekel Mashiach il 8 Lug 2022
Modificato: Torsten il 9 Lug 2022
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

Risposte (1)

Torsten
Torsten il 8 Lug 2022
Modificato: Torsten il 8 Lug 2022
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 Commenti
Dekel Mashiach
Dekel Mashiach il 9 Lug 2022
I need to do the integrations in real time
Torsten
Torsten il 9 Lug 2022
Modificato: Torsten il 9 Lug 2022
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by