how to put an array into a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi there!
the function "triu(X,1)" returns the upper trangular part of the matrix X. I now have an array of size 1-by-(0.5*n*(n-1)), exactly the number of elements in the upper triangular. How can I, without using any loop, put this array into a n-by-n matrix so that this matrix is what triu(X,1) returns?
Thanks. Lianovich
댓글 수: 0
채택된 답변
Walter Roberson
2011년 4월 10일
n = floor(sqrt(2*length(V)));
M = zeros(n);
M(logical(triu(ones(n),1))) = V;
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!