1

Is there an easy way to create a set of strings in Matlab?

I am going through a list of filepaths and want to get all names of folders at a specific level. But since in some folders there are several files, I get these folders several times.

I know there would be the possibility to create a cell array and check every time if the current folder name is already in the array, and if not, add it.

Another option would be to use the java HashSet class.

But is there any easy inbuilt Matlab way to do something like that? I can't use a Vector since it would create a vector of chars not strings.

4

3 回答 3

1

不幸的是,没有什么比 Java Set 实现更高效了。

但是您可以使用集合操作。无论union是当您添加时,还是只是使用重复项调用unique您的收藏。

于 2012-05-29T11:50:27.103 回答
1

您可以使用rdir脚本... MATLAB 文件交换来救援!

像这样使用它:

listing = rdir(name);

该函数返回一个listing类似于内置dir命令的结构。
它应该可以避免您自己遍历目录树的麻烦。

于 2012-05-29T11:52:56.233 回答
0

“独特”怎么样:

x = {'dog', 'cat', 'cat', 'fish', 'horse', 'bird', 'rat', 'rat'};    
x_set=unique(x)    
x_set =  
'bird'    'cat'    'dog'    'fish'    'horse'    'rat'
于 2013-05-08T20:25:35.663 回答