Unique elements in cell array

unique for numeric cell arrays. If c = {[0],[1,2],[0],[8],[1,2]} returns {[0],[1,2],[8]}

您现在正在关注此提交

function [Au, idx, idx2] = uniquecell(A)

Same as built-in unique, but works for cell arrays where each element is a numeric array.

For A a cell array of matrices (or vectors), returns Au, which contains the unique matrices in A, idx, which contains the indices of the last appearance of each such unique matrix, and idx2, which contains th indices such that Au(idx2) == A

Example usage:

A = {[1,2,3],[0],[2,3,4],[2,3,1],[1,2,3],[0]};
[Au,idx,idx2] = uniquecell(A);

Results in:

idx = [6,5,4,3]
Au = {[0],[1,2,3],[2,3,1],[2,3,4]}
idx2 = [2,1,4,3,2,1]

Algorithm: uses cellfun to translate numeric matrices into strings then calls unique on cell array of strings and reconstructs the initial matrices.

引用格式

Patrick Mineault (2026). Unique elements in cell array (https://ww2.mathworks.cn/matlabcentral/fileexchange/31718-unique-elements-in-cell-array), MATLAB Central File Exchange. 检索时间: .

致谢

启发作品: uniqueCellGeneralized(A), uniqueCells

类别

Help CenterMATLAB Answers 中查找有关 Characters and Strings 的更多信息

一般信息

MATLAB 版本兼容性

  • 兼容任何版本

平台兼容性

  • Windows
  • macOS
  • Linux
版本 已发布 发行说明 Action
1.0.0.0