Index exceeds number of array elements (1)??

1 Ansicht (letzte 30 Tage)
Cheng On ching
Cheng On ching am 11 Dez. 2019
Beantwortet: Nicolas B. am 11 Dez. 2019
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

Antworten (1)

Nicolas B.
Nicolas B. am 11 Dez. 2019
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.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by