Array indices must be positive integers or logical values.

조회 수: 2 (최근 30일)
Will
Will 2020년 4월 2일
댓글: Will 2020년 4월 2일
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;

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 4월 2일
편집: KALYAN ACHARJYA 2020년 4월 2일
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
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 4월 2일
편집: KALYAN ACHARJYA 2020년 4월 2일
% 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;
Will
Will 2020년 4월 2일
Oh I see I did a typo in the formula ... Thanks for pointing it out !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by