Displaying series of images in an axes in a GUI

Hi all, I have a GUI which has a axes in it apart from other elements. The functions called in callbacks generate different figures, say 5 in number. I want to display them in the axes one by one,such that user can see the previous or next image by pushing two push buttons provided. What is the best way to do this. Thanks in advance.

 采纳的回答

function testimg
figure
pbh = uicontrol(gcf,'Style','pushbutton','String','Next',...
'Position',[10 20 60 40],...
'callback',@newimg);
pbh1 = uicontrol(gcf,'Style','pushbutton','String','Previous',...
'Position',[10 50 60 40],...
'callback',@oldimg);
axes
text(0.2,0.5,'Press the buttons Next or Previous to see the images')
ImGN=1;
function newimg(obj,event)
showimg
ImGN=ImGN+1;
if ImGN>5
ImGN=1;
end
end
function oldimg(obj,event)
showimg
ImGN=ImGN-1;
if ImGN<1
ImGN=5;
end
end
function showimg(obj,event)
switch ImGN
case 1
spy
case 2
[X,Y,Z] = peaks(30);
surfc(X,Y,Z)
case 3
x = -2.9:0.2:2.9;
bar(x,exp(-x.*x),'r')
case 4
x = -2.9:0.2:2.9;
plot(x,sin(x))
case 5
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t)
grid on
axis square
end
end
end

1 个评论

Thanks a lot Silva. Though this is not exactly what i want, I don't have any better option, so I would go by this. Thanks to all.

请先登录,再进行评论。

更多回答(2 个)

Use the axes(H) command to set the current axis to your axis of choice
doc axes

5 个评论

Dear Sean,
I am doing that already. what i want is to allow user to go back and forth across a set of graphs generated, using two buttons 'prev' and 'next'. To put it clearly, the functions called in callbacks generate the plots which are displayed in the said axis as and when they are generated. Once the process stops, user should be able to view the plots in the same axes by using the 'prev' and 'next' buttons. Can u help me in this regard.
Hi Krishna,
using the axes handle should work as Sean already said. Without an example it is hard to tell what you are doing wrong. If you do have the axes handle you can use the plot(h,x,y) command to plot in the right axes
Hi greg,
I understand I didn convey it clearly. I have an axes and the two buttons(as described before) under it. I have a 'run' pushbutton which user presses after entering some options. The 'run' callback call a code package i have developed. The plots generated during evaluation of the codes are displayed in the lone axis provided as & when each of them is generated. I have no issue in that. What I am planning is to add a feature to this. After all codes are evaluated, the last plot would be visible in the axis. I want to allow users to access earlier plots too , in the same axis, using two pushbuttons, 'prev' and 'next'. Hope I am clearer now. Please Help.
Well if you already have the data then just cla (clear axis) and call plot again with the new data?
That seems to simple a solution, I don't think I'm understanding you correctly.
I suppose there isnt a better way. would go with Silva's suggestion.

请先登录,再进行评论。

I got what I wanted from this thread, courtesy 'ImageAnalyst'. The solution is simple and meats my needs.
Thanks all:)

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by