set current axis to plot in several subplots

4 ビュー (過去 30 日間)
Jahandar Jahanipour
Jahandar Jahanipour 2017 年 4 月 28 日
回答済み: Jahandar Jahanipour 2017 年 5 月 1 日
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,

採用された回答

Jahandar Jahanipour
Jahandar Jahanipour 2017 年 5 月 1 日
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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 4 月 29 日
imshow(my_image, 'Parent', left_handle)
(you would have to arrange for left_handle to be accessible in your callback.)
  1 件のコメント
Jahandar Jahanipour
Jahandar Jahanipour 2017 年 5 月 1 日
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)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by