How to produce square matrix in this form
    9 次查看(过去 30 天)
  
       显示 更早的评论
    
How can I form a square matrix in this form regardless of its dimension. Note that the pattern; 1 will form after three 0 from the centre.

0 个评论
采纳的回答
  Stephan
      
      
 2021-5-11
        k = 2; % define how often to repeat the pattern
result = toeplitz([5 repmat([1 0 0 0],1,k)])
gives:
result =
     5     1     0     0     0     1     0     0     0
     1     5     1     0     0     0     1     0     0
     0     1     5     1     0     0     0     1     0
     0     0     1     5     1     0     0     0     1
     0     0     0     1     5     1     0     0     0
     1     0     0     0     1     5     1     0     0
     0     1     0     0     0     1     5     1     0
     0     0     1     0     0     0     1     5     1
     0     0     0     1     0     0     0     1     5
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

