How to create an array

3 次查看(过去 30 天)
JRC
JRC 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 CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by