Cell array Numeric data splitting

조회 수: 1 (최근 30일)
Karthik Nagaraj
Karthik Nagaraj 2020년 11월 19일
댓글: Karthik Nagaraj 2020년 11월 26일
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.

답변 (1개)

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 19일
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
Karthik Nagaraj
Karthik Nagaraj 2020년 11월 26일
Without considering cell operation,
C = rand(N,N) + 1i*rand(N,N)
will yield only one matrix

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by