vector to upper and lower triangular matrix
古いコメントを表示
Hey, I'm new to Matlab and wanted to know how to input a 1 by n matrix and output a n by n matrix such that the diagonals are the mean of the 1 by n matrix and the upper and lower trianglars are elements of that 1 by n matrix. I have it working for the case n = 3 and here is my code:
A = [ 5 4 3];
a = [0 A(1) A(2);
A(1) 0 A(3);
A(2) A(3) 0];
A_ij = mean(A)*eye(length(A),length(A)) + a;

採用された回答
その他の回答 (1 件)
David Hill
2019 年 11 月 10 日
Not sure what elements you want above and below the diagonal.
a=repmat(A,[length(A),1]).*~diag(ones(1,length(A)))+mean(A)*eye(length(A));
カテゴリ
ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!