Cell array Numeric data splitting

1 visualización (últimos 30 días)
Karthik Nagaraj
Karthik Nagaraj el 19 de Nov. de 2020
Comentada: Karthik Nagaraj el 26 de Nov. de 2020
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); % Complex Matrix
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.

Respuestas (1)

Setsuna Yuuki.
Setsuna Yuuki. el 19 de Nov. de 2020
I think you don't need to use "cell" for C {j}, however you can use "cell" for V {j}.
something like that:
clearvars;
clc;
N=15;
k=6;
for j = 1:k
C = rand(N,N) + 1i*rand(N,N); % Complex Matrix
D = diag(C);
L = triu(C,1);
U = tril(C,-1);
V{j}= [D; real(U(:)); real(L(:))];
end
  1 comentario
Karthik Nagaraj
Karthik Nagaraj el 26 de Nov. de 2020
Without considering cell operation,
C = rand(N,N) + 1i*rand(N,N)
will yield only one matrix

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by