Index exceeds number of array elements (1)??

조회 수: 1 (최근 30일)
Cheng On ching
Cheng On ching 2019년 12월 11일
답변: Nicolas B. 2019년 12월 11일
function We = ProgramWe(d,pa,Vi,st)
st=0.073; % Surface tension (N/m)
pa=1.225; %The density of air(kg/m³)
%diameter of raindrops
We= (pa*Vi^d)/st;
end
The recall function shown above.
function Cdi = ProgramCd(We,a,b,c,Vi,dt,ti,tf)
a=0.013;
b=2.28;
c=2.12;
ti=0;
tf=12;
dt=2;
d=2;
t=ti;
pa=1.225;
st=0.073;
Vi=0;
V(1)=Vi;
i=2;
while(1)
if t+dt>tf, break,end
We = ProgramWe(d,pa,V(i-1),st);
Cd = 1+a*(We+b)^c -(a*b^c);
t=t+dt;
i=i+1;
end
Cdi=Cd;
The error of Index exceeds the number of array elements (1) appeared in ProgramCd (line 17)
We = ProgramWe(d,pa,V(i-1),st);
Any ideas? Thanks

답변 (1개)

Nicolas B.
Nicolas B. 2019년 12월 11일
Base on your code, I see that at line 13 of ProgramCd, you create V as a scalar because you even ensure that Vi must be of size 1.
If you want to have a vector V of e.g. 10, than:
V = zeros(1, 10); % or NaN(1, 10), ones(1, 10) depends with what you want to init V
V(1) = Vi; % initialize V(1) to Vi scalar value
Sorry to not be able to help more, but I don't know what you expect to have into V.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by