MATLAB: “Subscript indices must either be real positive integers or logicals.” again! See codes

codingindexinglogical?loopsrecallsubscript

Hi,
I have created two functions in Matlab. One is supposed to produce a concentration profile for a given location and time, but the current code gives this error "Subscript indices must either be real positive integers or logicals.". The second function, called testing, recalls the first function to do the calculation and uses loops instead, but still the same error is appearing.
1. Concentration profile code
function [c,t] = Disp_Conc(x,y,z,t)
%This function calculates the concentration of a an agent at a particular time and location
% Data generated through Dispersion model (This is a 1x61 vector)
[x,cc_x,b_x,betac_x,zc_x,sig_x,t,xc_t,bx_t,betax_t] = Read_Predict('predict');
% Time averaged volume concentration: concentration contour parameters
%erf = error function
sr2 = sqrt(2.0);
xa=(x-xc_t(t)+bx_t(t))/(sr2*betax_t(t));
xb = (x-xc_t(t)-bx_t(t))/(sr2*betax_t(t));
ya = (y+b_x(x))/(sr2*betac_x(x));
yb = (y-b_x(x))/(sr2*betac_x(x));
za = (z-zc_x(x))/(sr2*sig_x(x));
zb = (z+zc_x(x))/(sr2*sig_x(x));
c = (cc_x(x) * (erf(xa)-erf(xb)) * (erf(ya)-erf(yb)) * (exp(-za*za)+exp(-zb*zb)));
time=tm(t);
end
**Running this function, I get an error saying "Subscript indices must either be real positive integers or logicals." due to the fact that values of t and x are both fractional (both x and t are read from a 1×61 vector). To overcome this, I created another .m file that recalls the concentration function and uses loops as below:
2. Function "testing":
function [c, t] = testing( x,y,z,t )
%The values of x and t are already being read from a saved 1x61 vector. z and y can vary and must be specified by the user for a given location. The value of z should be set equal to zero for all cases and doesn't change.
for ts=1:length(t)
for xs=1:length(x)
z=0;
for y=0:100; %(k index?)
X=x(ts);
T=t(xs);
[c(ts),time(ts)]=Disp_Conc(X,y,z,T);
end
end
end
end
**Running "testing" for a particular parameters say testing(5,0,0,8.79), I get the below errors:
"Subscript indices must either be real positive integers or logicals.
Error in Disp_Conc (line 12)
xa=(x-xc_t(t)+bx_t(t))/(sr2*betax_t(t));
Error in testing (line 10)
[c(ts),time(ts)]=Disp_Conc(X,y,z,T);"
I don't know what is wrong this time? The original problem was because of indexing and now I still get the same error with the new function.
Any help would be greatly appreciated. Thx.

Best Answer

In the line that throws the error:
xa=(x-xc_t(t)+bx_t(t))/(sr2*betax_t(t));
what is the value of ‘t’?