How to divide vector to matrix(same row and column)

8 ビュー (過去 30 日間)
Kong
Kong 2020 年 3 月 27 日
編集済み: KSSV 2020 年 3 月 27 日
Hello.
I got some vector like (82580526 X 1)
I want to divide this vector to matrix. The matrix have same row and column. (N x N)
If it can't be divide equally, some row or column of the matrix can be splited.
Could you explain how to have same row and column?

採用された回答

KSSV
KSSV 2020 年 3 月 27 日
編集済み: KSSV 2020 年 3 月 27 日
To remove extra elements and convert to square matrix
A = rand(82580526,1) ;
l = length(A) ;
% GEt the nearest perfect square
N = floor(sqrt(l)) ;
% Reshape into required matrix
iwant = reshape(A(1:N*N),N,N) ;
To append zeros and convert to square matrix
A = rand(82580526,1) ;
l = length(A) ;
% GEt the next perfect square
N = ceil(sqrt(l)) ;
% Append zeros
A = [A ; zeros(N^2-l,1)] ;
% Reshape into required matrix
iwant = reshape(A,N,N) ;

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 3 月 27 日
If you have the Communications Systems Toolbox, then
buffer(TheVector, ceil(sqrt(numel(TheVector))))

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by