Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 用正则表达式搜索单元格数组_Matlab - Fatal编程技术网

Matlab 用正则表达式搜索单元格数组

Matlab 用正则表达式搜索单元格数组,matlab,Matlab,我经常发现自己试图搜索单元格数组,就像我想用sql查询搜索数据库一样。在本例中,我有许多军事基地(bases.shp) base=shaperead('us-millitary-bases.shp') 然后我想过滤形状文件以获得空军基地,类似于regexp({bases.FAC_NAME}','airforce')。但我得到的结果是相当麻烦的: [] [] [ 4] [] [] [ 9] [] 我确信过滤单元格数组或shapefile是很常见的,必须有一些好的实践。谢谢你的洞察力 我也在尝试类

我经常发现自己试图搜索单元格数组,就像我想用sql查询搜索数据库一样。在本例中,我有许多军事基地(bases.shp)

base=shaperead('us-millitary-bases.shp')

然后我想过滤形状文件以获得空军基地,类似于
regexp({bases.FAC_NAME}','airforce')
。但我得到的结果是相当麻烦的:

[]
[]
[ 4]
[]
[]
[ 9]
[]
我确信过滤单元格数组或shapefile是很常见的,必须有一些好的实践。谢谢你的洞察力

我也在尝试类似的事情:

trif = arrayfun(@(x)regexp(x.FAC_NAME,'Griff','match'),af_bases)

给定
regexp
的输出,只需检查结果单元格数组中的每个项是否为空,即可将其索引回原始单元格数组。您可以使用
cellfun
将函数应用于每个单元格

要获取逻辑数组,对于非空项,可以执行以下操作:

base_strings = {bases.FAC_NAME}';

ind = ~cellfun(@isempty, regexp(base_strings, 'Air Force'))
或者更干净地使用匿名函数:

ind = cellfun(@(x)( ~isempty(x) ), regexp(base_strings, 'Air Force'))
然后,要过滤:

filtered = base_strings(ind);