how to combine two array of cells into one cellwise
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
the cyclist
2021-11-27
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!