how to combine two array of cells into one cellwise

4 ビュー (過去 30 日間)
Mausmi Verma
Mausmi Verma 2021 年 11 月 27 日
回答済み: the cyclist 2021 年 11 月 27 日
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

採用された回答

the cyclist
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{:}
ans = 1×6
2 3 4 7 8 12
ans = 1×6
2 3 4 5 7 8
ans = 1×6
2 3 4 5 8 10
ans = 1×4
3 4 5 10

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by