How can I create a 22x22 Matrix from 231 values of the triangular matrix?

1 view (last 30 days)
I have 231 doubles which represent the values of one triangular of the complete matrix. I want to add the diagonal (all 1s) and the complementary triangular to get the full 22x22 matrix (which I need for the next task).
This is the closest I've got so far:
test = horzcat(tri,tri)
reshape(test,22,22,[])
Error using reshape
Product of known dimensions, 484, not divisible into total number of elements, 462.
The error is due to the fact that the diagonal (22x1) is missing, but I don't know how to add that...

Accepted Answer

Matt J
Matt J on 19 Jan 2021
Edited: Matt J on 19 Jan 2021
load(websave('Tri.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/493054/Tri.mat'));
N=roots([1,1,-2*numel(tri)])+1; %deduce the matrix dimensions
N(N<=0)=[];
idx=triu(true(N),1);
result=double(idx)+eye(N);
result(idx)=tri
result = 22×22
1.0000 0.2208 0.4880 0.4947 0.2733 0.3649 0.0302 0.2423 0.2521 -0.0407 0.3021 0.1282 -0.1977 0.4136 0.2318 0.0752 0.0599 0.4877 0.2686 -0.1919 0.0251 0.0543 0 1.0000 0.7913 0.4877 0.1072 0.1893 0.2650 0.3895 -0.0477 0.1563 0.5627 0.0351 0.3776 0.1872 0.4656 0.1598 0.0450 0.5441 -0.0250 -0.2780 -0.1442 -0.0107 0 0 1.0000 0.1311 0.3054 0.2138 0.4619 0.3481 -0.1696 0.2788 0.2901 0.3879 0.1732 0.4028 0.5422 0.6153 0.0933 0.5289 -0.3991 0.0534 -0.0662 0.5230 0 0 0 1.0000 -0.0548 -0.0903 0.7944 0.1480 -0.0469 0.2187 -0.0151 0.5569 0.2483 0.3056 0.0899 0.6903 0.1973 -0.2567 0.4054 0.3837 -0.0314 0.5232 0 0 0 0 1.0000 0.3347 0.3109 0.6274 0.1273 -0.2127 0.0853 0.1171 -0.2536 0.4088 0.1076 0.5081 0.1207 -0.2646 -0.5002 0.0302 0.1260 0.4296 0 0 0 0 0 1.0000 0.0140 0.4290 -0.1978 0.3986 0.3021 0.5588 0.3812 0.1024 0.6478 -0.1360 0.0285 0.0335 0.6610 0.2112 -0.2129 -0.1944 0 0 0 0 0 0 1.0000 0.0329 0.2104 0.6568 0.1223 0.4741 0.0456 0.0759 -0.2626 0.2613 -0.2659 -0.0490 0.2160 0.1493 0.2505 -0.3117 0 0 0 0 0 0 0 1.0000 0.0476 0.3159 -0.2352 0.2346 0.0961 0.2040 0.6898 -0.0124 0.7119 0.5553 -0.0067 -0.0415 0.4431 -0.1951 0 0 0 0 0 0 0 0 1.0000 0.1573 0.3977 0.3480 0.4854 0.2864 0.0616 0.0998 0.0775 -0.2745 0.3565 -0.0333 -0.2181 0.0910 0 0 0 0 0 0 0 0 0 1.0000 0.1360 -0.0104 0.6928 -0.3302 0.0644 0.0466 -0.0979 0.2668 0.5872 -0.1525 0.1251 0.3016

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!