フィルターのクリア

How to create an array

4 ビュー (過去 30 日間)
JRC
JRC 2017 年 7 月 19 日
コメント済み: Star Strider 2017 年 7 月 19 日
How to create an array
A = [0 0 0 0; 1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4]
using the command "for" or other?

採用された回答

Star Strider
Star Strider 2017 年 7 月 19 日
Use the repmat function:
A = repmat(0:4, 4, 1)';
A =
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
  2 件のコメント
JRC
JRC 2017 年 7 月 19 日
Perfect Star Strider!
I didn´t know the command "repmat".
Thank you.
Star Strider
Star Strider 2017 年 7 月 19 日
As always, my pleasure!
Another option for your particular problem is to use element-wise vector multiplication:
A = [0:4]'.*ones(1,4);
See the documentation on Array vs. Matrix Operations (link) for details.

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

その他の回答 (0 件)

カテゴリ

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