MATLAB: Drop Down and geoshow

drop downgeoshowMATLABshapefile

Hello !
I have an interface (GUI) that includes: Drop Down, Axes
In Drop Down I have 2 options: Map1, Map2
If you select Map1, it should display map1.shp; if you select Map2, it should display map2.shp
At startup, map1.shp is displayed
Problem: If I select Map2, it displays map2.shp correctly, but if I select Map1, nothing happens.
function startupFcn(app)
s=shaperead('C:\Users\Vostro\Desktop\App_Maps\Map1\map1.shp');
geoshow(app.UIAxes,s);
end
% Value changed function: SelecteazaHartaDropDown
function SelecteazaHartaDropDownValueChanged(app, event)
value = app.SelecteazaHartaDropDown.Value;
switch value
case 'Harta1'
s=shaperead('C:\Users\Vostro\Desktop\App_Maps\Map1\map1.shp');
geoshow(app.UIAxes,s);
case 'Harta2'
s=shaperead('C:\Users\Vostro\Desktop\App_Maps\Map2\map2.shp');
geoshow(app.UIAxes,s);
end
end

Best Answer

I am not seeing the issue with your code, but it could be improved a bit. Your initial value on the dropdown is the first one - 'Harta1', and if you opened the dropdown menu and pressed it again callback won't be executed, but that's not an issue because you have already loaded Harta1 in the startupFcn.
Better way to do it is by having an intial option that tells you to choose the map, as a result, you don't have to have the startupFcn anymore.
% Value changed function: SelecteazaHartaDropDown
function SelecteazaHartaDropDownValueChanged(app, event)
value = app.SelecteazaHartaDropDown.Value;
switch value
case 'Please select the map'
cla(app.UIAxes)
case 'Harta1'
s=shaperead('C:\Users\Vostro\Desktop\App_Maps\Map1\map1.shp');
geoshow(app.UIAxes,s);
case 'Harta2'
s=shaperead('C:\Users\Vostro\Desktop\App_Maps\Map2\map2.shp');
geoshow(app.UIAxes,s);
end
end