I created a zeros (n+1 by n+1) matrix. And I want the value 2*i on the row (2 : n)&(column 1:n-1) , where i is from 1 to n-1, how should I get that? Can anyone help me out?

1 次查看(过去 30 天)
I tried this :
n=4;
A=zeros(n+1);
for i=2:n-1
A([2:n,2:n-1])=[2*i]
end
But it didnt work

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-4-19
n = 4;
A = zeros(n);
A(2:n+1:end) = 2*(1:n-1);
A(n+1,n+1) = 0;

更多回答(1 个)

KSSV
KSSV 2017-4-19
n = 4 ;
A = zeros(n+1) ;
A(2:n,1:n-1) = repmat(2*(1:n-1),n-1,1) ;
  1 个评论
kingsley
kingsley 2017-4-19
编辑:kingsley 2017-4-19
Hi, KSSV. First of all, thanks for your effort! I might not be very clear on the requirement of the matrix. The attachment is the required matrix I need to make. And the xi is from 1 to n-1 Thanks !!!!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by