MATLAB: How to use the same equation to get shapes of different sizes and locations.

basic geometryshapes

Hi,
I'm trying to get 3 circles stacked ontop of eachother (a snowman) each of a different size (heights of: 80, 50, 30). I'm not sure how to use the same equation (given below) for each of the different parameters. I've tried using a matrix but matlab isn't liking that. Am I making an obvious mistake?
I want to make it look neat so don't want to write out the same equation multiple times.
angles = linspace(0, 2*pi, 500);
radius = [40 25 15];
CenterX = [0 0 0];
CenterY = [40 105 145];
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
plot(CenterX, CenterY, 'k+', 'LineWidth', 3, 'MarkerSize', 14);
grid on;
axis equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', 14);

Best Answer

Try this
angles = linspace(0, 2*pi, 500);
radius = [40 25 15];
CenterX = [0 0 0];
CenterY = [40 105 145];
for i = 1:length(radius)
for j = 1:length(angles)
x(i,j) = radius(i)*cos(angles(j)) + CenterX(i);
y(i,j) = radius(i)*sin(angles(j)) + CenterY(i);
end
end
plot(x(1,:), y(1,:), 'b-',x(2,:), y(2,:),'b', x(3,:), y(3,:),'b','LineWidth', 2);
hold on
plot(CenterX, CenterY, 'b+', 'LineWidth', 3, 'MarkerSize', 14);
grid
axis equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', 14);