diagonal matrix help, this is my code, not sure what to put for the D(i,j) part?

format long;
if (n~=4)&(n~=50)
'Input value must be 4 or 50'
return;
end
load(['data',num2str(n)],'A','b'); % load matrix A and b according to n
D=zeros(n,n); %Initialize D
%%%%%%%%%%%In the double-loop below, extract from A its diagonal part D,
for i=1:n
for j=1:n
if (i==j)
D(i,j) = ???;
end
end
end

 Accepted Answer

I would see if:
D(i,j) = A(i,j);
did what I wanted.

2 Comments

oh my god! Thank you, it works, dont know why i went blank .
My pleasure!
No worries! It happens to us all.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!