Array indices must be positive integers or logical values.
4 views (last 30 days)
Show older comments
Hello everyone,
I'm a bit rusty with Matlab since I didn't use it for a long time, but I struggle with a simple problem.
The problem is that I extracted this code from a book so I really expected it to work... It is about cell properties modelling.
When I run the code below I get the following error :
Array indices must be positive integers or logical values.
Error in test (line 39)
keff2 = k2 .*(am2(k1+2*k2)-2*am1*(k2-k1))./(am2*(k1+2*k2)-am1*(k1-k2));
Could anyone help me to figure it out ? I shoul have an array of values depending on the frequency but the code won't run.
Thanks a lot !
W.
% CMfactor.m
% the particle is assigned a conductivity kc1 and permittivity kp1.
% the suspending medium has conductivity kc2 and permittivity kp2.
% ki (i=1, 2) complex permittivity of particle, amd medium
% p0: permittivity of free space
% All parameters in SI Units (metres, S/m, F/m).
%
p0=8.854e-12;
% Membrane thickness d, cell raidus a2
d=7e-9;
a2=5e-6;
a1=a2-d;
f=logspace(3,9,120);
zeroline=f-f;
w=2*pi*f;
% Cytoplasme
kc1=0.8;
kp1=50*p0;
% Membrane
G=0.2;
kc2=G*d
C=8e-3;
kp2=C*d;
% kc1=10e-3;
% kp1=10*p0;
% kc2=10e-4;
% kp2=80*p0;
k1=kp1-i*kc1 ./w;
k2=kp2-i*kc2 ./w;
am1=a1^3;
am2=a2^3;
keff2 = k2 .*(am2(k1+2*k2)-2*am1*(k2-k1))./(am2*(k1+2*k2)-am1*(k1-k2));
rm = real(keff2)
plot(log10(f), rm, '-', log10(f),zeroline, '-');
text(6.2, 0.3,'Re'), text(5.2, -0.3, 'Im')
xlabel('Log Frequency (Hz)')
ylabel('Relative permittivity')
hold on;
0 Comments
Accepted Answer
KALYAN ACHARJYA
on 2 Apr 2020
Edited: KALYAN ACHARJYA
on 2 Apr 2020
keff2 = k2 .*(am2*(k1+2*k2)-2*am1*(k2-k1))./(am2*(k1+2*k2)-am1*(k1-k2));
More:
p0=8.854e-12;
% Membrane thickness d, cell raidus a2
d=7e-9;
a2=5e-6;
a1=a2-d;
f=logspace(3,9,120);
zeroline=f-f;
w=2*pi*f;
% Cytoplasme
kc1=0.8;
kp1=50*p0;
% Membrane
G=0.2;
kc2=G*d
C=8e-3;
kp2=C*d;
% kc1=10e-3;
% kp1=10*p0;
% kc2=10e-4;
% kp2=80*p0;
k1=kp1-i*kc1 ./w;
k2=kp2-i*kc2 ./w;
am1=a1^3;
am2=a2^3;
keff2 = k2 .*(am2*(k1+2*k2)-2*am1*(k2-k1))./(am2*(k1+2*k2)-am1*(k1-k2));
cmf=(k1-k2) ./(k1+2*k2);
rm=real(cmf);
im=imag(cmf);
rm = real(keff2)
plot(log10(f), rm, '-', log10(f), im, '-', log10(f),zeroline, '-');
text(6.2, 0.3,'Re'), text(5.2, -0.3, 'Im')
xlabel('Log Frequency (Hz)')
ylabel('Relative permittivity')
3 Comments
KALYAN ACHARJYA
on 2 Apr 2020
Edited: KALYAN ACHARJYA
on 2 Apr 2020
% CMfactor.m
% the particle is assigned a conductivity kc1 and permittivity kp1.
% the suspending medium has conductivity kc2 and permittivity kp2.
% ki (i=1, 2) complex permittivity of particle, amd medium
% p0: permittivity of free space
% All parameters in SI Units (metres, S/m, F/m).
%
p0=8.854e-12;
% Membrane thickness d, cell raidus a2
d=7e-9;
a2=5e-6;
a1=a2-d;
f=logspace(3,9,120);
zeroline=f-f;
w=2*pi*f;
% Cytoplasme
kc1=0.8;
kp1=50*p0;
% Membrane
G=0.2;
kc2=G*d
C=8e-3;
kp2=C*d;
% kc1=10e-3;
% kp1=10*p0;
% kc2=10e-4;
% kp2=80*p0;
k1=kp1-i*kc1 ./w;
k2=kp2-i*kc2 ./w;
am1=a1^3;
am2=a2^3;
keff2 = k2 .*(am2*(k1+2*k2)-2*am1*(k2-k1))./(am2*(k1+2*k2)-am1*(k1-k2));
rm = real(keff2)
plot(log10(f), rm, '-', log10(f),zeroline, '-');
text(6.2, 0.3,'Re'), text(5.2, -0.3, 'Im')
xlabel('Log Frequency (Hz)')
ylabel('Relative permittivity')
hold on;

More Answers (0)
See Also
Categories
Find more on Array Geometries and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!