close
clear
clc
mu0 = 4*pi*1e-7;
M0 = 1e3;
maxnum = 31;
rho1_min = 0;
rho1_max = 0.25;
xlimit = [-1, 1];
ylimit = xlimit;
zlimit = xlimit;
x = linspace(min(xlimit), max(xlimit), maxnum);
y = linspace(min(ylimit), max(ylimit), maxnum);
z = linspace(min(zlimit), max(zlimit), maxnum);
[Xg, Yg, Zg] = ndgrid(x, y, z);
rho = sqrt(Xg.^2 + Yg.^2 + Zg.^2);
phi = angle(Xg + 1i*Yg);
theta = angle(Zg + 1i*sqrt(Xg.^2 + Yg.^2));
RHO = sqrt(x.^2 + y.^2 + z.^2);
THETA = linspace(0, pi, 31);
PHI = linspace(0, 2*pi, 31);
F_x = cell(numel(RHO), numel(THETA), numel(PHI));
B1x = cell(numel(RHO), numel(THETA), numel(PHI));
for ii = 1:numel(RHO)
for jj = 1:numel(THETA)
for kk = 1:numel(PHI)
F_x{ii, jj, kk} = (RHO(ii)>= rho1_max) .* 2/3*M0*mu0 .* sin(theta) .* (RHO(ii) .* (sin(THETA(jj)) .* cos(theta) .* cos(PHI(kk)-phi) - cos(THETA(jj)) .* sin(theta)) ./ ...
(RHO(ii).^2 + rho1_max.^2 - 2.*RHO(ii) .* rho1_max .* (sin(THETA(jj)) .* sin(theta) .* cos(PHI(kk)-phi) + cos(THETA(jj)).* cos(theta))).^3/2) .* rho1_max.^2 .* sin(theta);
B1x{ii, jj, kk} = squeeze(-trapz(PHI,trapz(THETA,F_x{ii,jj,kk},2)));
end
end
end
1 Comment
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/562157-unable-to-perform-assignment-because-the-indices-on-the-left-side-are-not-compatible-with-the-size-o#comment_930548
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/562157-unable-to-perform-assignment-because-the-indices-on-the-left-side-are-not-compatible-with-the-size-o#comment_930548
Sign in to comment.