how to combine two array of cells into one cellwise
1 view (last 30 days)
Show older comments
I have two cell arrays with cells of different dimension and i want to combine them into one
as,
A={ [2,3 ; 2,7] [3,2 ;3,4 ;3,8] [4,3 ; 4,5] [5,4 ; 5,10] }
B={ [2,3,4 ; 2,3,8 ; 2,7,8 ; 2,7,12] [3,2,7 ; 3,4,5 ; 3,8,7] [4,3,2 ; 4,3,8 ; 4,5,10] [5,4,3] }
and I want answer to be like,
C={ [2,3,4,7,8,12] [2,3,4,5,7,8] [2,3,4,5,8,10] [3,4,5,10]
please help
0 Comments
Accepted Answer
the cyclist
on 27 Nov 2021
A={ [2,3 ; 2,7] [3,2 ;3,4 ;3,8] [4,3 ; 4,5] [5,4 ; 5,10] };
B={ [2,3,4 ; 2,3,8 ; 2,7,8 ; 2,7,12] [3,2,7 ; 3,4,5 ; 3,8,7] [4,3,2 ; 4,3,8 ; 4,5,10] [5,4,3] };
C = cellfun(@(x,y)union(unique(x),unique(y)).',A,B,'UniformOutput',false);
C{:}
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!