How to transform a cell array of cells in a matrix

6 ビュー (過去 30 日間)
ely may
ely may 2015 年 11 月 30 日
編集済み: Image Analyst 2015 年 12 月 1 日
Problem: I have a cell array and every cell of this array has an other cell that contains a string: I want to trasform the cell array in a matrix of strings. How can i do? I have tried to use cell2mat but matlab gives an error:
'Cannot support cell arrays containing cell arrays or objects.'
I have A, in the attached .mat file, which is a vector of strings, and I want to divide prefix to postfix. To do it I use this code :
for k=1:25
[matches(:,k), postfix(:,k)] = regexp(A,sprintf('%d%d(.*)',digits{1}(k),digits{2}(k)),'match','once','tokens');
end
This code creates postfix (attached matlab.mat). I want that postfix is a matrix, and I don't know how transform it.
  1 件のコメント
Star Strider
Star Strider 2015 年 11 月 30 日
編集済み: Star Strider 2015 年 11 月 30 日
The cell array in your ‘matlab.mat’ file seems to be 93% empty, and at least some of the non-empty cells contain only ''.

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

回答 (2 件)

Image Analyst
Image Analyst 2015 年 11 月 30 日
Extract it first, then use cell2mat:
for k = 1 : length(ca)
thisCellContents = ca{k}; % thisCellContents is another cell - the cell inside this cell.
matrix = cell2mat(thisCellContents);
end
Adapt as needed, for example if it's a 2D array of cells or whatever.
  3 件のコメント
Image Analyst
Image Analyst 2015 年 11 月 30 日
What did thisCellContents produce? Was there anything in it? Star Strider says your mat file is empty everywhere.
ely may
ely may 2015 年 12 月 1 日
編集済み: ely may 2015 年 12 月 1 日
the matlab.mat file is not empty everywhere: if you control, it isn't while thisCellContents is empty.
Star Strider:
The cell array in your ‘matlab.mat’ file seems to be 93% empty, and at least some of the non-empty cells contain only ''.

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


Stephen23
Stephen23 2015 年 11 月 30 日
編集済み: Stephen23 2015 年 11 月 30 日
>> X = {{'A'},{'bb'};{'CCC'},{'d'}}
X =
{1x1 cell} {1x1 cell}
{1x1 cell} {1x1 cell}
>> Y = reshape([X{:}],size(X))
Y =
'A' 'bb'
'CCC' 'd'
  6 件のコメント
ely may
ely may 2015 年 12 月 1 日
編集済み: ely may 2015 年 12 月 1 日
I have no secret! Now I post my code (I think it wasn't necessary). I add it in the question. Sorry but I think that the question was clear.
Image Analyst
Image Analyst 2015 年 12 月 1 日
Well it was necessary because we can now see that your code doesn't look like Stephen's code. Sorry, I have to leave for work now and I don't have time now to fix your code.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by