0
votes

I have a cell array containing 1x4 cells

A=
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>
<1x4 cell>  <1x4 cell>  <1x4 cell>

What I'm looking for is to make a cell array containing something like the following

B={'str1','str2','str3','str4';cell2mat(A{1,1})}

A cell array comes from another operations where the size in rows and columns can vary, so I would like to know weather or not this could be automatized using a for loop or something like that.

Edit: Sorry i would like to have an array B:

B{m,n}={'str1','str2','str3','str4';cell2mat(A{m,n})}

where m and n are the rows and columns of cell array A.

So lets say I have something like

A=
[1 2 3 4] [4 5 6 7] 
[8 9 10 11] [11 12 13 14] 

I would like to obtain an output B of the form

B{1}=
'str1' 'str2' 'str3' 'str4'
  1        2     3     4
  8        9    10   11
B{2}=
'str1' 'str2' 'str3' 'str4'
  4        5.      6       7
 11      12     13     14
1
be more specific and give us an example of one of the cells of A, and how you expect the corresponding cell in the output B to be.. - Amro
I'm afraid that is still not clear enough. What is the size of A and then the size of B? - Amro
you need to replace cell2mat with num2cell - Mohsen Nosratinia

1 Answers

0
votes

You could do:

B = cellfun(@(x) {'str1','str2','str3','str4',cell2mat(x)}, A, 'Uniform',false);

or

B = cellfun(@(x) ['str1','str2','str3','str4',x], A, 'UniformOutput',false);

depending on whether you want to "flatten" the elements or not in each cell. It's hard to tell without knowing what is inside each cell A{m,n}.