Forum Discussion
ogungbile
Mar 17, 2020Copper Contributor
Creating a Diagonal Matrix for a vector data
Good day to everyone. I am trying to create a diagonal matrix of dimension (900x900) from a vector data of n=900. Can someone guide me through how best I can generate the matrix? Thanks
ogungbile
Mar 17, 2020Copper Contributor
Thanks, I got the code already.
It is:
{=IF(A1:A3=TRANSPOSE(A1:A3),A1:A3,"0")}
Where A1:A3 indicates the vector column range. They can be adjusted as appropriate depending on the size of the vector column. For example, mine is a 900-cell vector. Therefore, I'll have:
{=IF(A1:A900=TRANSPOSE(A1:A900),A1:A900,"0")}
Thank you
- mikdaleJun 06, 2022Copper ContributorYou need to be careful using this approach, as it assumes that the values of the vector are unique, i.e. no two elements have the same value.