Make a matrix with ones and if

1 回表示 (過去 30 日間)
Josefine  Jonsson
Josefine Jonsson 2015 年 12 月 9 日
コメント済み: Josefine Jonsson 2015 年 12 月 9 日
Hi, I have a pretty simple question, but are kinda bad with ones(). I need to make a special matrix, for example, I have a 4 meter long and 2 meter width boat.
nx= 8 %Number of slices for x
hx= 4/nx %Steplenght for x
same for y
ny=8 %Number of slices for y
hy=2/ny %steplenght for y
I want a matrix:
A=[0 0 0 0 0 0 0 0
0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
1 1 1 1 1 1 1 1 osv]
so the number of rows will be nx+1 points, with x0=1, x1=xo+hx, x2=x1+hx and the number of columns will be ny+1 points, with the same value in each row.
A=[x0 x0 x0 x0(ny-times)
x1 x1 x1 x1(ny times)
x2 x2 x2 x2(ny-times)
for nx+1 rows)
I'm gonna continue take values from a function and want a 100x100 matrix so I really need help with the ones() in the matrix. A=ones(x0+1, ny) didn't work.

採用された回答

Matt J
Matt J 2015 年 12 月 9 日
xx=(0:nx)*hx +x0;
yy=(0:ny-1)*hy +y0;
[A,B]=ndgrid(xx,yy);
  1 件のコメント
Josefine  Jonsson
Josefine Jonsson 2015 年 12 月 9 日
OMG I love you, thanks!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by