Index exceeds the number of array elements. Index must not exceed 1.
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Could you please help me to solve the problem. I'm trying to calculate the difference between heights in a loop.
But it gives error "Index exceeds the number of array elements. Index must not exceed 1."
My code is
clear all; close all
W = 10000;
S = 40;
AR = 7;
cd0 = 0.005;
k = 1 / pi / AR;
j=0;
hv=6:-.01:0;
figure(1);hold on; xlabel('h');ylabel('V')
for h1=6:-.01:0
j=j+1;
cdminp=4*cd0;
rho1(j)=1.225*exp(-h1/10.4);
clminp=sqrt(3*cd0/k);
Vminp(j)=sqrt(2*W/rho1(j)/S/clminp);
dh(j)=h1(j)-h1(j+1);
end
figure(1); plot(hv, Vminp);
set(gca, 'XDir','reverse');
4 Commenti
Les Beckham
il 8 Feb 2023
If you know what the h1 vector is already, you don't need a loop to calculate the accumulated difference between elements of it.
h1=6:-.01:0;
dh = -cumsum(diff(h1));
dh(1:10) % look at the first ten elements
Risposte (1)
Dyuman Joshi
il 8 Feb 2023
You can do that without the loop
W = 10000;
S = 40;
AR = 7;
cd0 = 0.005;
k = 1 / pi / AR;
hv = 6:-.01:0;
cdminp = 4*cd0;
clminp = sqrt(3*cd0/k);
rho1 = 1.225.*exp(-hv./10.4);
Vminp = (2.*W./rho1./S).^(1/2);
dh = hv(1)-hv(2:end)
figure(1);
hold on;
xlabel('h');ylabel('V')
plot(hv,Vminp)
set(gca, 'XDir','reverse');
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!