Looking to plot yaw motion of an aircraft but get "Array indices must be positive integers or logical values." Error

조회 수: 2 (최근 30일)
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)));
>>

답변 (1개)

Harshavardhan
Harshavardhan 2025년 6월 26일
편집: Harshavardhan 2025년 6월 26일
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:
  • definePhias a vector using element-wise operations.
  • Use the gradient function to compute the numerical derivative for Phidot.
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:

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by