My requirement is to create generate numerous complex matrices of 15x15, and extract the diagonal elements and upper triangle elements as column vectors, and finally combine them into a single column vector.
As a part of the implementation I have done some code which looks similar to this.
I have created a program to generate 6 complex matrices using for loop, and stores them in a cell array.
Code 1:
clear all;
close all;
clc;
N=15;
k=6;
C=cell(k,1)
for j = 1:k
C{j}= rand(N,N) + 1i*rand(N,N);
end
Now the cell C 6 x1 contains 15x15 complex double numeric data in each cell array.
For extracting the diagonal elements extract the diagonal elements and upper triangle elements as column vectors and finally combine them into a single column vector for a Matrix C I have the following code.
Code 2:
D = diag(C)
L = triu(C,1)
U = tril(C,-1)
V= [D; real(U(:)); real(L(:))].
I would like to combine this Code 2 approach for the Cell C obtained in Code1 by splitting each array in cell C- 6x1 with 15x15 in each cell into differnt arrays/ matrices of 15x15 order and then do the code2 operation.
Is it better to use the cell array approach to create a loop of matrices, or is there any other way to do? Please guide me.
0 Comments
Sign in to comment.