How to create an array

조회 수: 5 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by