フィルターのクリア

Modifying a function (2D Plot and 3D Plot)

2 ビュー (過去 30 日間)
Aasiya Syed
Aasiya Syed 2020 年 4 月 26 日
コメント済み: Rena Berman 2020 年 5 月 14 日
  • I currently have a grid that goes from 1 to 20 for x and y.
function [ ] = make3DGrid( )
x=zeros(20*20,1);
y=zeros(20*20,1);
count = 1;
for i=1:20
for j=1:20
x(count) = i;
y(count) = j;
count = count+1;
end
end
  • How do I modify this function so that it takes 6 arguments (in this order): xmin, xmax, numx, ymin, ymax, numy. I want these to be the min and max ranges for a grid of data points.
  • Also, instead of having just the x and y variables, how could I modify the function to use/return a single matrix (gridXY) which would be a nx2 matrix of the x and y locations on the grid.
For the first part, I know linspace might be involved but I'm not sure. Any help would be appreciated! Thanks.
  2 件のコメント
Rik
Rik 2020 年 4 月 27 日
Why did you materially change your question? Now my answer doesn't make sense.
Rena Berman
Rena Berman 2020 年 5 月 14 日
(Answers Dev) Restored edit

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2020 年 4 月 26 日
編集済み: Rik 2020 年 4 月 26 日
Use linspace separately for x and y and then use meshgrid or ndgrid.
%create the vectors
x=linspace(xmin,xmax,numx);
y=____
%create the grid of all combinations
[x,y]=ndgrid(x,y);
%reshape x and y into vectors
x=x(:);
____
%create nx2 matrix
result=____
  4 件のコメント
Aasiya Syed
Aasiya Syed 2020 年 4 月 26 日
what should the result be ?
Rik
Rik 2020 年 4 月 26 日
If you fill in the missing parts of this code you will end up with two vectors. How would you make an nx2 matrix from two vectors?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by