Insert/Concatenate cell array into nested cell array (by column and repeat in each row)
Show older comments
I have CA a 1x3 cell array with {3x13 cell} {3x11 cell} {3x11 cell}. Each nested cell have 2x# double arrays.
Example CA{1} =
3×13 cell array
Columns 1 through 7
[2×153 double] [2×154 double] [2×156 double] [2×154 double] [2×156 double] [2×155 double] [2×154 double]
[2×153 double] [2×154 double] [2×156 double] [2×154 double] [2×156 double] [2×155 double] [2×154 double]
[2×153 double] [2×154 double] [2×156 double] [2×154 double] [2×156 double] [2×155 double] [2×154 double]
Columns 8 through 13
[2×151 double] [2×152 double] [2×152 double] [2×154 double] [2×154 double] [2×161 double]
[2×151 double] [2×152 double] [2×152 double] [2×154 double] [2×154 double] [2×161 double]
[2×151 double] [2×152 double] [2×152 double] [2×154 double] [2×154 double] [2×161 double]
I also have 3 individual cell arrays A {1x13 cell}, B {1x11 cell}, C{1x11 cell}. Each cell have 3x# double arrays.
Example A =
1×13 cell array
Columns 1 through 7
[3×153 double] [3×154 double] [3×156 double] [3×154 double] [3×156 double] [3×155 double] [3×154 double]
Columns 8 through 13
[3×151 double] [3×152 double] [3×152 double] [3×154 double] [3×154 double] [3×161 double]
I need to add/insert/concatenate A into each row of CA{1} to create:
CA_5{1} =
Columns 1 through 7
[5×153 double] [5×154 double] [5×156 double] [5×154 double] [5×156 double] [5×155 double] [5×154 double]
[5×153 double] [5×154 double] [5×156 double] [5×154 double] [5×156 double] [5×155 double] [5×154 double]
[5×153 double] [5×154 double] [5×156 double] [5×154 double] [5×156 double] [5×155 double] [5×154 double]
Columns 8 through 13
[5×151 double] [5×152 double] [5×154 double] [5×154 double] [5×161 double]
[5×151 double] [5×152 double] [5×154 double] [5×154 double] [5×161 double]
[5×151 double] [5×152 double] [5×154 double] [5×154 double] [5×161 double]
B corresponds to CA{2} and C to CA{3}.
I tried to use cellfun and arrayfun but I cannot get to re-concatenate into each row.
cellfun(@(x,y) [x;y], CA{1}, A,'uni',1);
Thanks
Accepted Answer
More Answers (1)
Dyuman Joshi
on 2 Mar 2023
Edited: Dyuman Joshi
on 2 Mar 2023
Change 'uniformoutput' to 0
CA{1}=cell(1,13);
A=cell(1,13);
for k=1:13
r=randi([2 4]);
%random data to show concatenation
A{k}=rand(r,156-k);
CA{1}{k}=rand(r,156-k);
end
CA{1}
A
%assign it accordingly
out{1} = cellfun(@(x,y) [x;y], CA{1}, A, 'uni', 0);
out{1}
%similarly for B and C as well
3 Comments
ErikaZ
on 2 Mar 2023
Dyuman Joshi
on 2 Mar 2023
Could you please attach your data via the paperclip button?
ErikaZ
on 2 Mar 2023
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!