Selecting more than one string value from a shapefile attribute
1 次查看(过去 30 天)
显示 更早的评论
I am working with the built-in shapefile 'usastatehi.shp' to select a group of states and draw them using geoshow. I currently have the following code:
IL = shaperead('usastatehi.shp','UseGeoCoords',true,...
'Selector',{@(name) strcmpi(name,'Illinois'),'Name'});
IN = shaperead('usastatehi.shp','UseGeoCoords',true,...
'Selector',{@(name) strcmpi(name,'Indiana'),'Name'});
OH = shaperead('usastatehi.shp','UseGeoCoords',true,...
'Selector',{@(name) strcmpi(name,'Ohio'),'Name'});
Is it possible to combine this into one statement?
0 个评论
回答(1 个)
Satwik
2025-4-21
Yes, the selection of multiple states can be combined into a single call to shaperead by having the selector function check if the state name is a member of a cell array containing the desired names. This can be done as follows:
states = {'Illinois','Indiana','Ohio'};
selectedStates = shaperead('usastatehi.shp', 'UseGeoCoords', true, ...
'Selector', {@(name) any(strcmpi(name, states)), 'Name'});
This approach makes the script more efficient and scalable.
I hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Map Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!