Hello,,(adsbygoogle = window.adsbygoogle || []).push({});

I try to convert a fortran program to matlab. I want to make an absorbing boundary model. But when I run it, I keep getting an error says:

??? Attempted to access w(12); index out of bounds because numel(w)=11.

Error in ==> absorb_bound_coba at 45

w(i)=exp(-1./d.^2.*(x(i)-lim4).^2*w(i));

%input

width=20

n=importdata('node.txt');

x=n(:,2);z=n(:,3);

%define constant

d=0.5*max(x);

w=1;

%computing boundary constant

boundary_width_x=width/100.*(max(x)+abs(min(x)));

boundary_width_z=width/100.*(max(z)+abs(min(z)));

lim1=min(x)+boundary_width_x;

lim2=max(x)-boundary_width_x;

lim3=min(z)+boundary_width_z;

lim4=max(z)-boundary_width_z;

%rectangular model

for i=1:length(x);

if x(i)<=lim1

w(i)=exp(-1./d.^2.*(x(i)-lim1).^2);

elseif x(i)>=lim2

w(i)=exp(-1./d.^2.*(x(i)-lim2).^2);

elseif z(i)<=lim3

w(i)=exp(-1./d.^2.*(x(i)-lim3).^2)*w(i);

elseif x(i)>=lim4

w(i)=exp(-1./d.^2.*(x(i)-lim4).^2)*w(i);

end;

end;

So how I can fix this?

Thanks in advance :D

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Index out of bound because numel(w)=11

**Physics Forums | Science Articles, Homework Help, Discussion**