Hi Asim,
I understand that you want to convert the given python code to MATLAB.
In the given Python code, the “region” variable is calculated using np.where(self.r >= self.R, 0, 1). This condition sets the value of region to 0 where self.r >= self.R and 1 otherwise.
To implement this in MATLAB, you can use logical indexing as shown below:
shape = [250,250,250];
N1=shape(1);
N2=shape(2);
N3=shape(3);
um = 1e-6;
c = 3e8; % m/s
dx = 4.8 * um;
dy = 4.8 * um;
dz = 4.8 * um;
dt = 1/4 * dx / c;
lamb = 74.9*um;
R = lamb*3/dx;
eps=10;
mu=1;
x = linspace(0,N1-1,N1);
y = linspace(0,N2-1,N2);
z = linspace(0,N3-1,N3);
[X,Y,Z] = meshgrid(x,y,z);
% X=(X(:))';
% Y=(Y(:))';
% Z=(Z(:))';
center = [125, 125,125];
r = sqrt((center(2)-X).^2 + (center(1)-Y).^2 + (center(3)-Z).^2);
epsr = ones(shape);
mur = ones(shape);
region = zeros(size(r));
region(r >= R) = 0;
region(r < R) = 1;
epsr = ones(shape);
epsr = epsr + region * (eps - 1);
smoothing = false;
% Calculate smoothing_region
smoothing_region = zeros(size(r));
if smoothing==true
temp = (0 < (r - R)) & ((r - R) < 1);
smoothing_region(temp) = 1/3 * (r(temp) + sqrt(r(temp).^2 - 1) - 2 * R).^2;
end
% Update epsr with smoothing_region
epsr = epsr + smoothing_region * (eps - 1);
You can refer to the following documentation on array indexing for more information on the use of logical indexing.
Hope this helps.