Plotting coordinate points using plot()
조회 수: 19 (최근 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에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!