MATLAB: 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

matrix manipulation

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

Best Answer

n = 4;
A = zeros(n);
A(2:n+1:end) = 2*(1:n-1);
A(n+1,n+1) = 0;
Related Question