how to separate the real and imaginary parts inside a cell

2 ビュー (過去 30 日間)
ANUSAYA SWAIN
ANUSAYA SWAIN 2024 年 9 月 10 日
回答済み: Anagha Mittal 2024 年 9 月 11 日
i have a cell of size 1X2. inside the cell there are 2 matrices of size 32X32. i want to separate the real and imaginary of both the matrices that is inside the cell the two matrices should be 32X32X2. and finally i want the size to be 2X32X32X2. How to do it.
  2 件のコメント
Anagha Mittal
Anagha Mittal 2024 年 9 月 10 日
Hi Anusaya,
Can you please share an example of the cell and the matrices for better understanding?
ANUSAYA SWAIN
ANUSAYA SWAIN 2024 年 9 月 10 日
like cell size is 1X2. inside the cell two matrices of size 32X32 are there. those matrices are complex double. Next i want to separate the real and imaginary parts of those two matrices and make the matrices size as 32X32X2. now the cell has two matrices of size 32X32X2. Next i want to convert that cell to matrix of final size 2X32X32X2.

サインインしてコメントする。

回答 (2 件)

Mathieu NOE
Mathieu NOE 2024 年 9 月 10 日
Maybe this ?
% create dummy data
n = 32;
for k = 1:2
cellarray{k} = k*ones(n,n)*(1+1i*5);
end
% process it
for k = 1:numel(cellarray)
out(k,:,:,1) = real(cellarray{k}); % extract / store real matrix
out(k,:,:,2) = imag(cellarray{k}); % extract / store imag matrix
end

Anagha Mittal
Anagha Mittal 2024 年 9 月 11 日
Hi,
Please find the below code for the same:
% Assuming 'cellArray' is your 1x2 cell array containing two 32x32 matrices and assigining with random values
% You may use your values
cellArray = {rand(32) + 1i*rand(32), rand(32) + 1i*rand(32)};
result = zeros(2, 32, 32, 2); % Final result will be stored in this
for i = 1:2
matrix = cellArray{i};
realPart = real(matrix);
imagPart = imag(matrix);
combinedMatrix = cat(3, realPart, imagPart); % Combining them into a 32x32x2 matrix
result(i, :, :, :) = combinedMatrix;
end
disp(result);
Hope this helps!

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by