Dear all,
I am trying to construct a matrix (or a grid) with specific limits on the x and y axes from two vectors:
ns = 20; %number of points on S axis
np = 20; %number of points on P axis
S = linspace(0,1,ns); %S variable
P = linspace(-1,1,np); %P variable
The resulting grid I want has the follwoing shape (just for an illustrative purpose. Surely the number of points would be larger):
I have thought about "meshgrid(S,P)" command, but it won't help as it doesn't let me have the specific P limits that I want, as shown in the photo above.
Any help would be appreicated!
Thanks,
Lama

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 12일

0 개 추천

meshgrid creates the matrices of x and y coordinates you wlil need to plot a mesh/surface plot.
Lookin at the examples on the mesh documentation page for how to use these two functions.

댓글 수: 4

Lama Hamadeh
Lama Hamadeh 2021년 3월 12일
Thank you for your answer. However, although meshgrid will generate a grid of the same size that I want, but it won't let me access each grid cell (or pixel) of the grid. Also, it would be hard (I guess) to strict the limit of the y axis to be from -1 to 1 and the x axis to be from 0 to 1. When using meshgrid, it generates two axes with the same limits.
Cris LaPierre
Cris LaPierre 2021년 3월 12일
편집: Cris LaPierre 2021년 3월 12일
Meshgrid does not create axes. It creates matrices that can be used as the coordinates (x and y, or in your case, S and P).
To place a point in a 2D grid, you need the X and Y values. To access a value, you need its index number in the vector/matrix.
ns = 20; %number of points on S axis
np = 20; %number of points on P axis
s = linspace(0,1,ns); %S variable
p = linspace(-1,1,np); %P variable
[S,P] = meshgrid(s,p);
% mesh needs X,Y and Z so create z
Z = zeros(size(S));
mesh(S,P,Z,'Marker','o','MarkerFaceColor','k','EdgeColor',"k")
axis equal tight
view(2)
Lama Hamadeh
Lama Hamadeh 2021년 3월 12일
Great! Many thanks!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2021년 3월 12일

댓글:

2021년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by