How to transpose a cell array blockwise?
古いコメントを表示
I have created a dataset D with one column and 3 rows which includes the following elements:
D1 = {1, 1} , 'Text1' with a total repetition of 15 times (1 row and 15 columns)
D2 = {2, 1} , Includes 15 300x3 double elements (1 row and 15 columns) named data1
D3 = {3, 1} , 'Text2' with a total repetition of 15 times (1 row and 15 columns)
Therefore I have the following cell array if i open D1, D2, and D3:
Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1 Text1
data1 data1 data1 data1 data1 data1 data1 data1 data1 data1 data1 data1 data1 data1 data1
Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2
When using the transpose option I would like to get the following order:
Text1
data1
Text2
Text1
data1
Text2
Text1
data1
Text2
etc.
However I am not sure how to write the code for it properly. Is there a matlba function to create "block elements" for transposing the above mentioned example?
Stay safe and healthy
David
5 件のコメント
James Tursa
2021 年 3 月 3 日
Can we assume that the D elements are themselves cell arrays? I.e., you have a nested cell array and D{1,1} is a 1x15 cell array?. And you desire to have an unnested cell array result that is 45x1?
Stephen23
2021 年 3 月 3 日
David Mrozek
2021 年 3 月 3 日
Bjorn Gustavsson
2021 年 3 月 3 日
This sounds like a rubbish structure for your data (I might be wrong, and I know this sounds harsh.) The structure you chose for your data should make the work simple, here you seem to combine the data in a way that makes further processing difficult.
I suggest you take a think about how you should structure the data in a way that makes it easy to process.
David Mrozek
2021 年 3 月 3 日
編集済み: David Mrozek
2021 年 3 月 3 日
採用された回答
その他の回答 (1 件)
Bjorn Gustavsson
2021 年 3 月 3 日
If I understand you right this should do what you want:
QWE = {'T1_1','T1_2','T1_3';randn(1),randn(2),randn(3);'T2_1','T2_2','T2_3'};
%
%QWE =
%
% 3×3 cell array
%
% 'T1_1' 'T1_2' 'T1_3'
% [0.5377] [2×2 double] [3×3 double]
% 'T2_1' 'T2_2' 'T2_3'
%
QWE(:)
%
%
%
% 9×1 cell array
%
% 'T1_1'
% [ 0.5377]
% 'T2_1'
% 'T1_2'
% [2×2 double]
% 'T2_2'
% 'T1_3'
% [3×3 double]
% 'T2_3'
This should extend well.
HTH
1 件のコメント
David Mrozek
2021 年 3 月 3 日
編集済み: David Mrozek
2021 年 3 月 3 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!