GUI GUIDE Error with Map

I'm trying to insert a map into the GUI GUIDE and I'm getting the error:
"Error while evaluating uicontrol Callback"
The map does work when I run it standalone in the command
window but when I push the button in GUIDE, it appears then gets
distorted, and then
I get an error.
Here is my code:
function temp_button_Callback(hObject,eventdata,handles)
lat = [80 45 52; 45 46 34]
long = [123 132 123; 120 122 119]
temp = [67 68 69; 71 72 73]
axesm('mercator','MapLatLimit',[-50 90],'MapLonLimit',[0 250])
framem on; gridm on;
load coast;
mlabel on;
plabel on;
plotm(lat,long,'k')
contourfm(long,lat,temp)
Thanks,
Amanda

 Réponse acceptée

Matt Fig
Matt Fig le 23 Août 2012
Modifié(e) : Matt Fig le 23 Août 2012

0 votes

You clear long and lat, then immediately try to use them. This is your error. You also rely on Poofing variables into your workspace... This is a very bad habit you should break while the debugging is easy!
lat = [80 45 52; 45 46 34];
long = [123 132 123; 120 122 119];
temp = [67 68 69; 71 72 73];
axesm('mercator','MapLatLimit',[-50 90],'MapLonLimit',[0 250])
framem on; gridm on;
X = load('coast'); % No variable Poofing!!
mlabel on;
plabel on;
plotm(X.lat,X.long,'k')
contourfm(long,lat,temp)

13 commentaires

Amanda
Amanda le 23 Août 2012
Nope. That was a typo. I clear it out and still seeing the same error.
Matt Fig
Matt Fig le 23 Août 2012
I posted example code that doesn't rely on variable poofing. When I run it I get no errors. Did you try the above? If so and you still get an error, please post the entire error message and the entire contents of the callback function.
Amanda
Amanda le 23 Août 2012
Did you run it in GUIDE? It is a clean run in the script.
Amanda
Amanda le 23 Août 2012
Modifié(e) : Amanda le 23 Août 2012
What is happening is Push button temp is interfering with another push button on guide. It is not clearing it out.
Matt Fig
Matt Fig le 23 Août 2012
No, I don't have your GUI, so I cannot run it. I assume your GUI has an axes object for plotting? What happens if you put this as the very first line of the callback:
figure
And do you still get an error when you used the alternate code I posted above? And if so, where is the whole error message?
Amanda
Amanda le 23 Août 2012
A figure plot windows appear outside the GUI.
Amanda
Amanda le 23 Août 2012
What is happening is that it appears and a click another push button for a graph and it plots that on top of the previous plot
Matt Fig
Matt Fig le 23 Août 2012
I see. If you only want one plot at a time, simply put this in before each time you plot:
cla
This clears the axes to accept another plot. So if you have many pushbuttons each plotting a different thing, the in each callback put cla in first. So now we know that the code does not error when plotting to another figure. Does it still error when plotting to the GUI axes?
Matt Fig
Matt Fig le 23 Août 2012
I made a simple GUI in guide. One with only an axes and a pushbutton. I then put the code I gave above in the callback for the pushbutton of the GUI. Here is what I got (no errors):
Amanda
Amanda le 23 Août 2012
Make another push button and plot a line plot. Then you will see the line plot plotted on top of the map.
Matt Fig
Matt Fig le 23 Août 2012
Not if I put cla in the callback for the line-plotting-pushbutton. Here is the callback for the new pushbutton:
cla
plot(1:10)
No line on the map. Did you want a line on the map?
Amanda
Amanda le 23 Août 2012
Thanks so mush for helping me. Let try this. I've been at this for 3 hours.
Amanda
Amanda le 23 Août 2012
That is it. Thanks so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by