Farshad Khodamoradi
Farshad Khodamoradi

Reputation: 179

how to put The main diameter in magic(9) with diag in a matrix 3 * 3?

this is my code,i want to put the result of diag in a matrix 3*3 in Matlab,how to create it?

a=magic(9);
b=diag(a);

i want to put the result of b in a matrix 3*3

Upvotes: 0

Views: 105

Answers (2)

Marcus Müller
Marcus Müller

Reputation: 36442

c = reshape(b,[3,3])

will reshape your 1x9 matrix b into a 3x3 matrix c

Upvotes: 2

madbitloman
madbitloman

Reputation: 826

You can do it by reshaping your array:

c=reshape(b,3,3)

Upvotes: 2

Related Questions