Error Msg: Subscript indices must either be real positive integers or logicals

1 visualizzazione (ultimi 30 giorni)
B=1.21; mu=.92; ct=8.72e-6; poro=.21; rw=4/12; h=50; pi=5000; s=0; k=200; ra=sqrt(100^2+500^2); rc=sqrt(300^2+500^2); qa=300; qc=500; pwfb=zeros(1,10000); hold on
for t=0.1:0.1:1000 i=t*10; if t<48 pwfb(1,i)=pi-(70.6*qa*B*mu/k/h)*expint(948*ra*ra*poro*mu*ct/k/t); else pwfb(1,i)=pi-70.6*qa*B*mu/k/h*expint(948*ra*ra*poro*mu*ct/k/t)-70.6*qc*B*mu/k/h*expint(948*rc*rc*poro*mu*ct/k/(t-48)); end end
I get the error mentioned above when I run this code. The error is in line after the conditional IF.
Can someone please explain this error and how to overcome it.
I need to plot all the values that I get from PWF againt T.
Thanks alot!

Risposta accettata

Roger Stafford
Roger Stafford il 24 Feb 2014
Modificato: Roger Stafford il 24 Feb 2014
Your problem is caused by the fact that not all values of i will be exact integers, and that is due to the round-off errors in representing the value 0.1. The double precision floating point numbers matlab is using cannot achieve 0.1 exactly, so when you multiply their multiples by ten, the result is occasionally not an exact integer.
In your for-loop you should have written:
for i = 1:10000
t = i/10;
rather than
for t=0.1:0.1:1000
i=t*10;
to ensure integer values for i.
By the way, you should never call any of your variables 'pi'. That is a reserved word in matlab standing for the universal ratio between a circle's circumerence and its diameter. When you redefine it as you have, you may receive some unpleasant surprises along the way.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by