how to combine two array of cells into one cellwise

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

the cyclist
the cyclist il 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{:}
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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by