How to divide vector to matrix(same row and column)
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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) ;
댓글 수: 0
추가 답변 (1개)
Walter Roberson
2020년 3월 27일
If you have the Communications Systems Toolbox, then
buffer(TheVector, ceil(sqrt(numel(TheVector))))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!