- define“Phi”as a vector using element-wise operations.
- Use the “gradient” function to compute the numerical derivative for “Phidot”.
Looking to plot yaw motion of an aircraft but get "Array indices must be positive integers or logical values." Error
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
clear all
clc
N_phidot = -0.36752;
N_phi = -8.3569;
N_delta_r = -3.8313;
delta_R = -10;
sigma = 1/2.*N_phi;
omega_d = (-N_phi-1/4.*(-N_phidot)^2)^(1/2);
xi = 1/2.*(-N_phidot/-N_phi^(1/2));
omega_n = (-N_phi)^(1/2);
beta = (N_delta_r/N_phi).*delta_R;
phi = atan(sigma/omega_d);
alpha = -1/2.*beta.*(omega_n/omega_d);
Tau = 2*3.14/omega_d;
xiomega_n = 1/Tau;
t = [0:0.01:10];
Phi(t) = beta.*(1-(omega_n/omega_d.*exp(-sigma.*t).*cos((omega_d.*t)-phi)));
Phidot(t) = diff(Phi(t));
figure(1)
plot(t,phidot)
title('Phidot vs time')
xlabel('seconds')
ylabel('degrees')
figure(2)
plot(t, phi)
title('Phi vs time')
xlabel('seconds')
ylabel('degrees')
Error Messages
Array indices must be positive integers or logical values.
Error in HW1MAE503Q2 (line 22)
Phi(t) = beta.*(1-(omega_n/omega_d.*exp(-sigma.*t).*cos((omega_d.*t)-phi)));
>>
0 Commenti
Risposte (1)
Harshavardhan
il 26 Giu 2025
Modificato: Harshavardhan
il 26 Giu 2025
MATLAB expects indices to be positive integers or logical values. You're trying to assign values to “Phi(t)”, which is interpreted as indexing into “Phi” using the values of “t”, which are not valid indices.
To fix this:
Here is the updated code for the definitions of “Phi” and “Phidot”:
% Phi and Phidot
Phi = beta .* (1 - (omega_n / omega_d) .* exp(-sigma .* t) .* cos((omega_d .* t) - phi_val));
Phidot = gradient(Phi, t);% Numerical derivative
For more information on “gradient” refer to the link below:
0 Commenti
Vedere anche
Categorie
Scopri di più su Historical Contests in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!