How to reconstruct a cell with different sizes from a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I have a cell array of complex double and I want to convert them to matrix for the next process. Then, I want to reconstruct back the matrix to cell array. I do like the following codes, where I try with a simple input cells. I know this is not a good method to do, because when I try to change the input into a bigger size, it hard to manually code the position of the cells. Is there any efficient way to do this? Thank you in advance
clc
clear all
% Input cells
F = {{[0.04,0.2,0.56;0.31,0.67,0.22]},{...
[6+6j,7+3j,8-6j;6+8j,7-6j,3-3j],...
[5+6j,8+5j;6+8j,7-6j;5+6j,3-9j],...
[6+6j,7+3j,8-6j;6+8j,7-6j,3-3j],...
[5+6j,8+5j;6+8j,7-6j;5+6j,3-9j]},{...
[16+6j,7+3j,8-6j;6+8j,7-6j,3-3j],...
[16+6j,7+3j,8-6j;6+8j,7-6j,3-3j]},{...
[0+0j,0+0j;0+0j,0+0j;0+0j,0+0j]}}
% Extract the cells
G={}
dim = 2
for k=1:length(F)
G = [G,F{k}]
end
% Convert the cell to matrix
B = catpad(dim,G{:})
% Delete NaN in the matrix
V = B(~isnan(B))
% Another process apply to the matrix
%%%%%%%%%%%%%%%
% Inverse Reconstruction:
% Convert the matrix to cell
H =num2cell(V)
% Reshape the cell
M1 = {}
M = H'
for s=1:6
M1 = [M1,M{s}]
end
M1s = [M1(1) M1(3) M1(5); M1(2) M1(4) M1(6)]
M1s = cell2mat(M1s)
M2 = {}
for s=7:18
M2 = [M2,M{s}]
end
M2s{1,1}{1,1} = [M2{1,1} M2{1,3} M2{1,5};M2{1,2} M2{1,4} M2{1,6}]
M2s{1,1}{1,2} = [M2{1,7} M2{1,10}; M2{1,8} M{1,11}; M{1,9} M2{1,12}]
M3 = {}
for s=19:24
M3 = [M3,M{s}]
end
M3s = [M3(1) M3(3) M3(5); M3(2) M3(4) M3(6)]
M3ss = cell2mat(M3s)
M4 = {}
for s=25:30
M4 = [M4,M{s}]
end
M4s = [M4(1) M4(3); M4(5) M4(2); M4(4) M4(6)]
M4ss = cell2mat(M4s)
% Combine all cells to become only one cell aray
% Create 1x4 cells
C = {M1s {M2s{1,1}{1,1} M2s{1,1}{1,2}} M3ss M4ss}
11 Kommentare
Jan
am 27 Sep. 2022
Bearbeitet: Jan
am 27 Sep. 2022
Just a hint: Replace
G={};
dim = 2;
for k=1:length(F)
G = [G,F{k}];
end
by
G = [F{:}];
and
M2 = {}
for s=7:18
M2 = [M2,M{s}]
end
by
M2 = [M{7:18}];
But the main problem is the switching from cells of cells to cells to numerical arrays and the other way around. What is the purpose of this confusing procedure?
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!