Plotting coordinate points using plot()
32 次查看(过去 30 天)
显示 更早的评论
```
rng (7)
n = 30;
center = [0 0];
radius = 1;
eps = 0.1;
r = eps*rand(n,1) + radius -eps/2;
A = [center(1) + r.*cos(2*pi*(1:n)'/n) center(2) + r.*sin(2*pi*(1:n)'/n)]
```
In above code the matrix A has two columns and 30 rows, column 1 x-coordinate and column 2 y-coordinate of a point (x,y)
How can I plot those 30 points with plot() function?
I tried (very new to Matlab syntax and all so I just used a transpose of A since I had dealt with that 2*n matrix point plotting before but it gives me no points, but compiles)
```
transposeA = transpose(A);
plot(transposeA(1, :),transposeA(2, :), 'k.','MarkerSize', 1);
```
I found this method to plot a circle with my center + radius I found for least squares to the 30 points and I want to add the plot for the points to the hold on/off
```
angles = linspace(0, 2*pi, 500);
radius = sqrt(1.00380009);
CenterX = 0.0179;
CenterY = -0.0069;
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);
hold off
```
0 个评论
回答(2 个)
KSSV
2020-9-26
rng (7)
n = 30;
center = [0 0];
radius = 1;
eps = 0.1;
r = eps*rand(n,1) + radius -eps/2;
A = [center(1) + r.*cos(2*pi*(1:n)'/n) center(2) + r.*sin(2*pi*(1:n)'/n)]
%%
angles = linspace(0, 2*pi, 500);
radius = sqrt(1.00380009);
CenterX = 0.0179;
CenterY = -0.0069;
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
figure
hold on
plot(A(:,1),A(:,2))
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);
hold off
0 个评论
Ameer Hamza
2020-9-26
编辑:Ameer Hamza
2020-9-26
It is giving you points, but the size is so small that they are barely visible. Also, transpose is not needed here. The following line is equivalent.
rng (7)
n = 30;
center = [0 0];
radius = 1;
eps = 0.1;
r = eps*rand(n,1) + radius -eps/2;
A = [center(1) + r.*cos(2*pi*(1:n)'/n) center(2) + r.*sin(2*pi*(1:n)'/n)];
plot(A(:,1), A(:,2), 'k.', 'MarkerSize', 20);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!