独特的细胞载体 [英] Unique cell vectors

查看:60
本文介绍了独特的细胞载体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在单元格数组中找到唯一的数组.假设我有6个具有以下向量的单元格:

I try to find unique arrays in a cell array. Suppose I have 6 cells with the following vectors:

a{1}=[1 2];
a{2}=[1 2 3];
a{3}=[2 3 4];
a{4}=[1 2];
a{5}=[1 2 3];
a{6}=[2 3 4];

然后结果应为[1 2][1 2 3][2 3 4].我使用了u=(cellfun(@unique,a,'Un',0)),但是它不起作用,该怎么办?

Then the result should be [1 2], [1 2 3] and [2 3 4]. I used u=(cellfun(@unique,a,'Un',0)), but it doesn't work, How can I do this?

推荐答案

以下是解决方法:

u = unique(cellfun(@num2str,a,'Un',0));

将它们转换回vector:

To transform them back to vector :

u2 = cellfun(@str2num,u,'Un',0);

这篇关于独特的细胞载体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆