How to create an array
    6 次查看(过去 30 天)
  
       显示 更早的评论
    
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?
0 个评论
采纳的回答
  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 个评论
  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);
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

