Index exceeds the number of array elements. Index must not exceed 1.
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Les Beckham
2023 年 2 月 8 日
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
回答 (1 件)
Dyuman Joshi
2023 年 2 月 8 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!