Selecting more than one string value from a shapefile attribute
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Satwik
le 21 Avr 2025
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 commentaires
Voir également
Catégories
En savoir plus sur Map Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!