A matrix/grid from two vectors

34 ビュー (過去 30 日間)
Lama Hamadeh
Lama Hamadeh 2021 年 3 月 12 日
コメント済み: Lama Hamadeh 2021 年 3 月 12 日
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 日
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 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 3 月 12 日
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 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by