How to extract diagonal elements of multiple nxn square matrix and place them in single mat file or matrix?
9 views (last 30 days)
Show older comments
Sunny on 27 Sep 2018
I have 500 mat files with 10x10 double dimension. I want to extract the 10 diagonal elements from each matrix and place them in a single matrix which will be 500x10 (500 rows and 10 columns) each row consists of diagonal elements of one matrix. How can I make a single variable with all the diagonal elements?
ytzhak goussha on 27 Sep 2018
Hope this helps
step1:creat a nXnXm with random elements for the example:
%set dimensions of matrix
step2: initialize an output matrix with nXm dimensions
step3: extract a diagonal from each matrix and place them in the output matrix
Alternatively, though not recommended, you can simply concatenate:
%initialize an empty matrix
More Answers (0)
Find more on Creating and Concatenating 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!