Forum Discussion

ogungbile's avatar
ogungbile
Copper Contributor
Mar 17, 2020

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's avatar
    ogungbile
    Copper Contributor

    Thanks, I got the code already.

    Savia 

    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 

     
     
     
     
     
     
     
     
     

    • mikdale's avatar
      mikdale
      Copper Contributor
      You 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.
  • Savia's avatar
    Savia
    Steel Contributor
    Can you explain what you need a little more? I know Excel but I don't know as much about matrices 🙂 A workbook or even an image would help a lot to explain.
    • ogungbile's avatar
      ogungbile
      Copper Contributor

      ok, Thanks.Savia 

       

      I have a single column that has 900 cells contained with data. I want to split these 900-cell vector data into a diagonal matrix with each data on the column spread across the diagonal of the matrix formed. e.g. say a1=2, a2=3 and a3=5....I want a diagonal matrix that will have a1=2, b2=3,c3=5 etc. with other cells of the matrix having "0" values.

       

       

      • Savia's avatar
        Savia
        Steel Contributor

        ogungbile Thanks, that helped a lot.

         

        I attach a file with both a traditional formula approach and one based on the newer dynamic array functions (Office 365 only).

Resources