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;
更多回答(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!