Axes are not refreshing in Matlab GUIDE

In a GUI application , placed a pop-up-menu, with two values 1 & 2. When the index of pop-up-menu is changed I want to plot a figure in gui ( not in a separate window) . Below code is written under pop-up-menu callback function, its working but the axis and titles are not updating or refreshing.
menuIndex = get(handles.popupmenu1, 'value');
figure;
if menuIndex == 1
plot(1:10);
title('title1');
else
plot(sin(1:10));
title('title2');
end
ax = findobj(gcf,'type','axes','-or','Tag','legend','-or','Tag','Colorbar');
hCopy= copyobj(ax, handles.figure1);

 Risposta accettata

menuIndex = get(handles.popupmenu1, 'value');
fig = handles.figure1;
ax = axes('Parent', fig);
if menuIndex == 1
plot(ax, 1:10);
title(ax, 'title1');
else
plot(ax, sin(1:10));
title(ax, 'title2');
end
Nothing needs to be moved because it is all drawn in the proper figure in the first place.

3 Commenti

It is over writing title and axes values .
Your existing code creates a new axes in a figure and copies that axes in to figure1, effectively adding another axes to figure1, but with whatever position information happened to be automatically generated for when it was in temporary figure. Is that the behaviour you want, that the code should add an additional axes to what already exists, and place the axes where-ever it feels like it?
If you have an existing axes that you want the drawing to go into then you would use its handle. For example if handles.axes1 was the axes you wanted used then:
menuIndex = get(handles.popupmenu1, 'value');
ax = handles.axes1;
if menuIndex == 1
plot(ax, 1:10);
title(ax, 'title1');
else
plot(ax, sin(1:10));
title(ax, 'title2');
end
With regards to overwriting the title and axes marks: your initial posting was about it not overwriting the title and axes marks, and now you seem to be objecting to the fact that it does overwrite the title and axes marks. If you do not want the title and axes marks overwritten, then are you wanting additional titles to be added to the plots?
Yes now its working. Thanks

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by