Array incompatible issue in for loop for plotting the small circles

3 次查看(过去 30 天)
clear all
N=2
Lx=10
Ly=50
R=30
n=48
smallrad=3
meanG1x=75;
meanG1y=30000;
stddevG1x=Lx/0.6745;
stddevG1y=Ly/0.674;
for i=1:N
center1x=normrnd(meanG1x,stddevG1x,i,1);
center1y=normrnd(meanG1y,stddevG1y,i,1);
center1 = [center1x,center1y]; % circle centers
radius1 = repmat(R, i, 1); % circle radii
%for small circles
r1 = R*(rand(n,i));
t1= 2*pi*rand(n,i);
x1 = center1x + r1.*cos(t1);
y1 = center1y + r1.*sin(t1);
center1n=[x1,y1];
radius1n=repmat(smallrad,n,1);
for Circle1 = size(center1, 1):-1:1
% Approximate each circle with a 1000-sided polyshape
C1(Circle1) = nsidedpoly(1e3, ...
'Center', center1(Circle1, :), ...
'Radius', radius1(Circle1));
end
for Circle1n = size(center1n, 1):-1:1
% Approximate each circle with a 1000-sided polyshape
C1n(Circle1n) = nsidedpoly(1e3, ...
'Center', center1n(Circle1n, :), ...
'Radius', radius1n(Circle1n));
end
end
plot(C1)
hold on
plot(C1n)
hold off

采纳的回答

Voss
Voss 2022-4-9
Without knowing the intent of the code, it's hard to say how to fix it, but here's an attempt:
clear all
N=2;
Lx=10;
Ly=50;
R=30;
n=48;
smallrad=3;
meanG1x=75;
meanG1y=30000;
stddevG1x=Lx/0.6745;
stddevG1y=Ly/0.674;
for i=1:N
center1x=normrnd(meanG1x,stddevG1x,i,1);
center1y=normrnd(meanG1y,stddevG1y,i,1);
center1 = [center1x,center1y]; % circle centers
radius1 = repmat(R, i, 1); % circle radii
%for small circles
r1 = R*rand(n,i);
t1 = 2*pi*rand(n,i);
x1 = center1x.' + r1.*cos(t1);
y1 = center1y.' + r1.*sin(t1);
% center1n=[x1,y1];
% radius1n=repmat(smallrad,n,1);
center1n=[x1(:),y1(:)];
radius1n=repmat(smallrad,n*i,1);
for Circle1 = size(center1, 1):-1:1
% Approximate each circle with a 1000-sided polyshape
C1(Circle1) = nsidedpoly(1e3, ...
'Center', center1(Circle1, :), ...
'Radius', radius1(Circle1));
end
for Circle1n = size(center1n, 1):-1:1
% Approximate each circle with a 1000-sided polyshape
C1n(Circle1n) = nsidedpoly(1e3, ...
'Center', center1n(Circle1n, :), ...
'Radius', radius1n(Circle1n));
end
end
plot(C1)
hold on
plot(C1n)
hold off
axis equal

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by