Index exceeds number of array elements (1)??

1 次查看(过去 30 天)
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