Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses

I am trying to a legend graph of position versus time by running this code and its giving me a lot of errors. First error is "Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax
error. To construct matrices, use brackets instead of parentheses." Please help!
varInput = load('quadData.mat');
qDat = varInput.quadrotor;
[n,~] = size(qDat);
Xi_0 = [qDat(1,2:4)'; qDat(1,8:10)'];
v = qDat(:,5:7);
omega = qDat(:,11:13);
t=qDat(:,1);
dt=qDat(2,1) - qDat(1,1);
T_initial = qDat(1,1);
T_final = qDat(end,1);
phi=qDat(:,8);
th=qDat(:,9);
psi=qDat(:,10);
q_tr=[cos(0.5*psi).*cos(0.5*th).*cos(0.5*phi)+sin(0.5*psi).*sin(0.5*th).*sin(0.5*phi),cos(0.5*psi).*cos(0.5*th).*sin(0.5*phi)-sin(0.5*psi).*sim(0.5*th).*cos(0.5*phi),cos(0.5*psi).*sin(0.5*th).*cos(0.5*phi)+sin(0.5*psi).*cos(0.5*th).*sin(0.5*phi),sin(0.5*psi).*cos(0.5*th).*cos(0.5*phi)-cos(0.5*psi).*sin(0.5*th).*sin(0.5*phi)]
Xi_0=[qDat(1,2:4)';q_tr(1,:)'];
pose_dot(1,Xi_0,dt,v,omega);
[t_out,Xi] = ode45(@pose_dot,[T_initial T_final],Xi_0);
figure
plot(t_out,Xi(:,4:7),':');
hold on
plot(t,q_tr,'-');
legend('q_0', 'q_q','q_2','q_3','q_{0,true}','q_{1,true}','q_{2,true}','q_{3,true}');
grid on
title('Quanternions vs. Time Graph');
xlabel('Time s');
ylabel('Quanternion');
figure
plot(t_out,Xi(:,1:3),':');
hold on
plot(t,qDat(:,2:4),'-');
legend('x_{calc}','y_{calc}','z_{calc}','x_{true}','y_{true}','z_{true}');
grid on
title('Position vs. Time');
xlabel('Time s');
ylabel('Position m');
function Xi_dot = pose_dot(t,Xi,dt,v,omega)
ind = floor(t/dt) + 1;
nu = [v(ind,:)'; 0.5*Xi(4:7)];
q0 = Xi(4);
q1 = Xi(5);
q2 = Xi(6);
q3 = Xi(7);
Xi_dot=[q0^2+q1^2-q2^2-q3^2 2*(q2q1-q0*q3) 2*(q3*q1+q0*q2) 0 0 0 0;2*(q2q1+q0*q3) q0^2-q1^2+q2^2-q3^2 2*(q3*q2-q0*q1) 0 0 0 0;2*(q3*q1-q0*q2) 2*(q3*q2-q0*q1) q0^2-q1^2-q2^2+q3^2 0 0 0 0;0 0 0 0 -omega(ind,1) -omega(ind,2) -omega(ind,3);0 0 0 omega(ind,1) 0 omega(ind,3) -omega(ind,2);0 0 0 omega(ind,2) -omega(ind,3) 0 omega(ind,1);0 0 0 omega(ind,3) omega(ind,2) -omega(ind,1) 0]*nu;
end

Réponses (1)

I've spotted two errors so far.
(1) Where you have
0.5th
where you presumably want
0.5*th
(2) In that same line, you typo'ed sin() once as sim().

4 commentaires

Fixed it, it is still giving me error!
I get the error that pose_dot has too many inputs. I could not find anything about that function.
I removed the if statment because it was making the trouble try it as I edit it please?
Just a guess, but did you mean
q2*q1
instead of
q2q1
?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by