How to format a cell array

Hi,
Quick question here. I have a 1x15 cell which contains 15 24x1 double (i.e 15 cells, each containing 24 numbers). Is there an easy way to convert this into any other format? Say a 1x360 cell ? Or anything else that's actually easy to use?
Thank you

回答 (2 件)

Gopichandh Danala
Gopichandh Danala 2017 年 2 月 3 日

1 投票

% pre-process to get data
tempcell = cell(1,15);
for i = 1:15
for j = 1:24
tempcell{i}(j,1) = rand(1);
end
end
% tempcell = 1 * 15 cells with 24 *1 elements in each cell
% format all cell elements into a array
Singlearray = reshape(cell2mat(tempcell),[],1); % sort to a column vector
Singlearray2 = reshape(cell2mat(tempcell),1,[]); % sort to a row vector
Let me know if this is what you want, Gopi
Stephen23
Stephen23 2017 年 2 月 3 日
編集済み: Stephen23 2017 年 2 月 3 日

0 投票

The simplest would be as a simple numeric array, so use:
cell2mat(X)
Or, if you really want a cell array, then try:
num2cell(cell2mat(X))
possibly followed by a reshape. Personally I would just put the data into one numeric array: much simpler and faster to work with.
Whatever you do do not use loops for this. Loops are a slow and inefficient way to solve tasks like this.

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

製品

タグ

質問済み:

2017 年 2 月 3 日

編集済み:

2017 年 2 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by