set current axis to plot in several subplots

14 visualizzazioni (ultimi 30 giorni)
I have a figure with two subplots I have defined the subplots as:
figure_handle = figure('Tag', 'main_figure');
right_hanlde = subplot(121,...
'Tag','right_plot',...
'Units', 'normalized');
left_handle = subplot(122,...
'Tag', 'left_plot',...
'Units','normalized',...
'Position',[.51 0.03 .496 .917]);
I have a pushbutton that plots my image.
uicontrol('style', 'pushbutton',...
'Units', 'normalized',...
'Position', [.56 .88 .02 .02],...
'String','plot',...
'Callback',@plot_Callback)
function plot_callback(hObject,~)
imshow (my_image);
end
The problem is that if I click anywhere in the right subplot, the current axis is going to be set on the right plot and if I push the plot pushbuttom, it shows my image on the right subplot.
I want to have a line of code in my callback function before "imshow" to set the axis on the right_plot.
Also, the subplot(122) does not work in my case because I have several other properties that by calling subplot() they are all going to be reset.
Thanks,

Risposta accettata

Jahandar Jahanipour
Jahandar Jahanipour il 1 Mag 2017
I found the answer, in case someone else needs to use:
first, in the gui, we have to save the handles in the guidata (in case someone is not familiar with gui data - help guidata)
handles.left_handle = left_handle; % store the wanted handle in the handles sturcture
handles.right_handle = right_handle; % store the wanted handle in the handles sturcture
guidata(figure_handle,handles) % save all the handles in the guidata of the figure
in the callback function we can easily set the current axes of the current figure to the handle that we want:
function Callback_function(hObject,~)
handles = guidata(hObject) % call all the handles that we saved
set(gcf,'CurrentAxes',handles.left_handle) % set the current axis of the current figure to the handle that we want
imshow(...) % show the image that we want
end

Più risposte (1)

Walter Roberson
Walter Roberson il 29 Apr 2017
imshow(my_image, 'Parent', left_handle)
(you would have to arrange for left_handle to be accessible in your callback.)
  1 Commento
Jahandar Jahanipour
Jahandar Jahanipour il 1 Mag 2017
I pass the left_handle to the guidata and it is accessible in my callback. But I get the following error:
Error using imshow>validateParent (line 352) HAX must be a valid axes handle.
Error in imshow (line 251) validateParent(specific_args.Parent)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by