Matlab:如何计算单元中存储了多少个唯一的字符串? [英] Matlab: How to calculate how many unique strings are stored in the cell?

查看:96
本文介绍了Matlab:如何计算单元中存储了多少个唯一的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个带有字符串值的单元格,我想计算其中存储了多少个不同的值.以下是示例值:

Given a cell with string values I would like to count how many different values are stored in it. The following ae the example values:

A(1, 1) = 'DA4590162D037A78D96557AA886ADF9715B79C75';
A(2, 1) = 'AFAB19476C2CEEEE101FFA45FD207BA8B6185B29';
A(3, 1) = '99C1F96461BC870574D002034F001BA3F96A9AB5';
...
A(8, 1) = '99C1F96461BC870574D002034F001BA3F96A9AB5';
A(9, 1) = '4B7F0F39C1192D12E6C798143981048D01CDDDD3';
...

大约有3M行.有谁知道计算结构中存储多少个唯一值的方法?

There are approximately 3M rows. Does anyone know the way to calculate how many unique values are stored in the structure?

谢谢!

推荐答案

B = UNIQUE(A)对于数组A返回与A中相同的值,但是 没有重复. B也将被排序. A可以是 字符串.

B = UNIQUE(A) for the array A returns the same values as in A but with no repetitions. B will also be sorted. A can be a cell array of strings.

所以

U = unique(A, 'rows'); %because each string is one row
numUnique = length(U)

这篇关于Matlab:如何计算单元中存储了多少个唯一的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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