合并多个单元格阵列

Jér*_*uté 3 arrays merge matlab cell

我的单元阵列S <1x4cell>包含4门单元阵列(<108x1cell>,<106x1cell>,<111x1cell>,<115x1cell>),其中每个都包含大约一百文件的路径列表.

我想合并它们以便获得一个包含所有路径的单个单元格.这样做有一个功能吗?

the*_*alk 5

连接您的单元格数组并使用unique:

%// example data
A ={'a';
     'b';
     'c';
     'd'};
B = {'a';
     'e';
     'f'};
C = {'g';
     'a';
     'c'};

%// merge cells
merged = [A(:); B(:); C(:)]
%// or
merged = cat(1, A(:), B(:), C(:))

%// remove duplicates
filtered = unique(merged)
Run Code Online (Sandbox Code Playgroud)

或者假设你已经有了单元格数组S = merged,请执行以下操作:

S = { A, B, C }

%// remove duplicates
filtered = unique(cat(1,S{:}))
Run Code Online (Sandbox Code Playgroud)