Reading mat-files from one cell to another cell array

Hi friends,
i have a matrix with cell (88 * 1), every row has a matrix with 30*768*20 double, where 20 is an (epochs).
I want to reconcatinate it to separted epoches (30*1), so for first row will be reconcatinated to 20 *88 *768 times of (30*1).
the final matrix will 1351680*1
I have tried it manually, but it's going to take a long time, but i believe its going to be easy using for loops.
for i= 1:20
for s=1:88
for d=1:768
O1=squeeze(XTrain{s,1}(:,:,i));
G= O1 (:,d);
end
end
end
O={G};

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 12 月 9 日

0 投票

Something like this. Look for function reshape().
O=XTrain;
for s=1:88
O{s}=reshape(XTrain{s},x,y,z);
end

4 件のコメント

Abdulhakim Alezzi
Abdulhakim Alezzi 2020 年 12 月 10 日
Dear Fangjun,
It does not work.
Fangjun Jiang
Fangjun Jiang 2020 年 12 月 10 日
That is not informative. Provide a simple example data and explain the desired result.
Abdulhakim Alezzi
Abdulhakim Alezzi 2020 年 12 月 11 日
I have a matrix (XTrain) with (88*1) cell. In every row of XTrain matrix, i have 30*768*20 double, as shown in figure above.
I want to reshape the cell matrix to have (30*1 only) by concatenating (768*22*88).
The final matrix will be (1351680*1) cell, where every row will represnet (30*1).
Fangjun Jiang
Fangjun Jiang 2020 年 12 月 11 日
Follow this example, play out how you want to flat the matrix, use shiftdim() if needed
%%
XTrain=repmat({rand(3,7,2)},8,1);
Out=cell2mat(XTrain');
Out=reshape(Out,3,[]);
Out=Out';
Out=mat2cell(Out,ones(1,112),3);

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

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

製品

リリース

R2020b

質問済み:

2020 年 12 月 9 日

コメント済み:

2020 年 12 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by