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
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}
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.