显示 更早的评论
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
采纳的回答
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 个评论
Nope. That was a typo. I clear it out and still seeing the same error.
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.
Did you run it in GUIDE? It is a clean run in the script.
What is happening is Push button temp is interfering with another push button on guide. It is not clearing it out.
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?
A figure plot windows appear outside the GUI.
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
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?
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):

Make another push button and plot a line plot. Then you will see the line plot plotted on top of the map.
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?
Thanks so mush for helping me. Let try this. I've been at this for 3 hours.
That is it. Thanks so much!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
