Plotting coordinate points using plot()

```
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
```

Risposte (2)

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
Ameer Hamza
Ameer Hamza il 26 Set 2020
Modificato: Ameer Hamza il 26 Set 2020
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);

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by