matlab: cell合并/拼接 数组/array/matrix 去重

1. cell合并/拼接

字符串、向量、矩阵、cell数组拼接

cell1={[1,1],[2,1,1]};
cell2={[2,2],[2,1,1,5]};
res=[cell1,cell2];%列拼接
res=[cell1;cell2];%行拼接

2. 数组/array/matrix 去重

数组或矩阵中的去除重复元素

另参考 string比较

% 第一种方法
r_integer = [1,3,2,2,2,3,5,6,7];
r_NonRepeating1 = unique(r_integer); % 去掉重复元素,但会打乱顺序

% 第二种方法
[~,j] = unique(r_integer,'first');
r_NonRepeating2 = r_integer(sort(j)); % 未打乱顺序的去重

% 第三种方法
[r_NonRepeating3,~] = unique(r_integer,'stable'); % 第三种方法是最好的!

你可能感兴趣的:(Matlab,matlab)