How to transfer a figure to a GUI?

조회 수: 4 (최근 30일)
Meshooo
Meshooo 2016년 2월 3일
댓글: Meshooo 2016년 2월 3일
Dear all,
I want to add a push button to a figure, so I used this code
I = imread('cameraman.tif');
figure, imshow (I);
uicontrol('Style', 'pushbutton', 'String', 'SAVE',...
'Position', [20 20 50 20],...
'Callback', ...
@yourCallback);
Now, how to show this figure in the GUI's axis after pressing the button?
I used the following code before, but now not working in Matlab2015b
uicontrol('Style', 'pushbutton', 'String', 'SAVE',...
'Position', [20 20 50 20],...
'Callback', ...
@yourCallback);
function yourCallback(ObjH, EventData)
I = getimage;
setappdata(0, 'I', I);
resXGui; %the name of the GUI
Is there any alternative way to do that?
Any help will be appreciated.
Meshoo
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2016년 2월 3일
Meshoo - is that all the code there is to your callback? What does getimage do (isn't a handle to the figure where the image shown needed)? Is resXGui a different GUI that you wish to transfer the image to?
Please show all of your code (for this callback) and comment on what is happening or is supposed to b e happening. You say that I used the following code before, but now not working in Matlab2015b. Please clarify what part of the code is not working. Discuss what you observe and what you wish to observe. If any errors are being generated then copy and paste the full error message to your question.
Meshooo
Meshooo 2016년 2월 3일
편집: Meshooo 2016년 2월 3일
OK, I will try to make it clearer. I have a "Main_GUI" and want to transfer an image to another GUI which called resXGui. The image will open in the axes of resXGui. One of the push buttons in resXGui will import this image from axes and open it separately as a figure window and let me add lines to the image. Now after adding the lines, I want to return back the image to resXGui axes. So the following code was there such that a push button will appear in the "figure" window and made it transferred to resXGui.
function varargout = resXGui(varargin)
function pushbutton1_Callback(hObject, eventdata, handles)
I = getimage; % get the image from resXGui
figure, imshow (I)
1- do something
2- return I to the resXGui, and for that used this code
uicontrol('Style', 'pushbutton', 'String', 'SAVE',...
'Position', [20 20 50 20],...
'Callback', ...
@yourCallback);
function yourCallback(ObjH, EventData)
I = getimage;
setappdata(0, 'I', I);
resXGui; %the name of the GUI
This works normally in matlab2014, but I couldn't do it in matlab2015b. Now when calling resXGui from Main_GUI, I cann't open this resXGui anymore and this error shows
Error: File: resXGui.m Line: 442 Column: 10
Function with duplicate name "yourCallback" cannot be defined.
Error in Main_GUI>pushbutton13_Callback (line 487)
resXGui; %the name of the threshold GUI
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Main_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Main_GUI('pushbutton13_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
So that's all and thank you for consideration.

댓글을 달려면 로그인하십시오.

답변 (1개)

Stalin Samuel
Stalin Samuel 2016년 2월 3일
I = imread('cameraman.tif');
hb = uicontrol('Style','pushbutton',...
'String','Click here',...
'Callback','imshow(I)');
  댓글 수: 4
Stalin Samuel
Stalin Samuel 2016년 2월 3일
Meshooo
Meshooo 2016년 2월 3일
Right, I got that idea from that link before and it was working normally. But in matlab2015b it is not working.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by