Subscript indices must either be real positive integers or logicals.
4 views (last 30 days)
Show older comments
I have this code:
%Deposition by diffusion - still air
d_k = [1.81, 1.414, 1.115, 0.885, 0.706, 0.565, ...
0.454, 0.364, 0.286, 0.218, 0.162, 0.121, ...
0.092, 0.073, 0.061, 0.049, 0.048, 0.039, ...
0.037, 0.035, 0.033, 0.030, 0.028, 0.024]*10^-2; %Airways diameter
R_k=d_k/2;
l_k=[12.456, 3.614, 2.862, 2.281, 1.78, 1.126 ...
0.897, 0.828, 0.745, 0.653, 0.555, 0.454,...
0.357, 0.277, 0.219, 0.134, 0.109, 0.091,...
0.081, 0.068, 0.068, 0.068, 0.065, 0.073]; %airways lenght
n=0; %besselzero inputs: n,k,kind
k=5;
kind=1;
am0=besselzero(n,k,kind); % bessel roots
Co=1;
k_bol=1.38*10^(-23); %J/K
T=310; % Kelvin
dp=0.01; %μm
Cc=23.06; % for d=0.01μm
visc=1.8*10^(-5); %kg/ms
D=k_bol*T*Cc*10^6/(3*pi*visc*dp) %m^2/s
%---------------------------------------------%
syms tp
dcdr_R=sym(zeros(1,24));
deposition=sym(zeros(1,24));
dep=zeros(9,24);
for N=1:24
syms tp
assume(tp,'real')
for k=1:5
dcdr_R(N)=@(tp) dcdr_R(N)+2*Co/(am0(k)*besselj(1,am0(k)))*exp(-(am0(k))^2*D*tp/(R_k(N))^2)*(-am0(k)/R_k(N))*besselj(1,am0(k));
end
deposition(N)=@(tp) (2*pi*R_k(N)*l_k(N))*(-D*dcdr_R(N));
for t=1:5
dep(t,N)= dep(t,N)+subs(deposition(N),tp,t);
end
end
I want to run it for t=1:.5:5, but when I do that i take the following error:
Subscript indices must either be real positive integers or logicals.
Should I define the array dep as something else? Please help me, I am new in matlab!!!!
Thanks in advance!
2 Comments
Stephen23
on 5 Sep 2019
"I want to run it for t=1:.5:5"
What is the 1.5th row of dep?
You seem to be confusing indices with data.
Answers (1)
Stephen23
on 5 Sep 2019
It is much simpler to iterate over indices, than iterating over data values. So rather than this:
for t = 1:5 % iterate over data (avoid this)
...
end
you should be doing something like this:
TV = 1:0.001:5; % data vector
for k = 1:numel(TV) % iterate over indices (simpler)
t = TV(k);
...
end
Note that
1.0001,1.0002,... data
1st, 2nd,... indices
2 Comments
Stephen23
on 5 Sep 2019
Eleni Parasxaki's "Answer" moved here:
Okay it worked! Thank you very much for your time and your help!:)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!