building a square matrix out of a vector

Hi everyone,
im trying to build a [n X n] matrix from a [1 n*n] vector. can anybody give me a simple code?

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 8 Mär. 2014
Bearbeitet: Mischa Kim am 8 Mär. 2014

0 Stimmen

Hossein, use reshape:
A = 1:4*4;
n = sqrt(length(A)); % if A is indeed an n*n vector
B = reshape(A,n,n)

Weitere Antworten (0)

Gefragt:

am 8 Mär. 2014

Kommentiert:

am 8 Mär. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by