Plot a nx2 matrix as points

조회 수: 57 (최근 30일)
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio 2023년 7월 18일
편집: Pranavkumar Mallela 2023년 7월 27일
Hello, I have different nx2 matrices as outputs from earhquake signals, where n can vary. I would like to plot these matrices as points where n is the number of points and the first and second columns contain the x and y value for each point. Let us say I have a matrix A as follow:
A[0.5 2; 1.0 -0.8; 1.5 -2.5]
Herein, (0.5,2), (1.0, -0.8), and (1.5, -2.5) would the coordinates of the points I would like to plot. Thank you for your response.

채택된 답변

Torsten
Torsten 2023년 7월 18일
이동: Torsten 2023년 7월 18일
A=[0.5 2; 1.0 -0.8; 1.5 -2.5];
plot(A(:,1),A(:,2),'o')
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 7월 18일
One can also use scatter -
A = [0.5 2; 1.0 -0.8; 1.5 -2.5];
scatter(A(:,1),A(:,2),'r*')
axis('equal')
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio 2023년 7월 18일
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Pranavkumar Mallela
Pranavkumar Mallela 2023년 7월 18일
편집: Pranavkumar Mallela 2023년 7월 27일
Hi Jorge,
I understand that you want to plot the points obtained from a given nx2 matrix.
It can be done by extracting the x, y coordinates using array indexing. The graph can be plotted using the 'plot' function. Using '-*' in the 'plot' function will help you see the points.
Please find the code below:
A = [0.5 2; 1.0 -0.8; 1.5 -2.5]
A = 3×2
0.5000 2.0000 1.0000 -0.8000 1.5000 -2.5000
x = A(:,1)
x = 3×1
0.5000 1.0000 1.5000
y = A(:,2)
y = 3×1
2.0000 -0.8000 -2.5000
plot(x, y, '-*')
For more information regarding extracting points, please refer the following documentation: https://www.mathworks.com/help/matlab/math/array-indexing.html
For more information regarding the 'plot' function, please refer the following documentation: https://www.mathworks.com/help/matlab/ref/plot.html
Hope this helps! Thanks!
  댓글 수: 1
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio 2023년 7월 18일
Hi. Thank you for your answer. However, I do not want to plot a line, I just want to plot them as shaded points on top another plot that contains the earthquake signal as lines.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by