How can I pass Axes (GUI) into a function
Show older comments
I am designing a function that is supposed to show a picture on an axes if a certain if condition is satisfied. eg:
%GUI PUSHBUTTON CALLBACK
function PushButton_Callback(hObjects,eventdata,handles)
while(1)
Image1 = imread('image1.png')
Image2 = imread('image2.png');
Out_Fun = MyFun (Image1,Image2,axes1); %axes1 is a drawn axes in the GUI
end
---------------------------------
%MyFunction
function [Output] = MyFun (Image1,Image2,axes1)
corr = corr2(Image1,Image2);
if (corr == 1)
axes(handles.axes1)
imshow('SAME FIG.png');
else
axes(handles.axes1)
imshow('NOT SAME FIG.png');
So my question is how can I pass the axes1 handle to MyFun so that I can use it inside the function
Answers (2)
Azzi Abdelmalek
on 13 Jun 2013
by handles
function []=yourfunction(handles,...)
2 Comments
Shadi Al Mahallawy
on 13 Jun 2013
Edited: Shadi Al Mahallawy
on 13 Jun 2013
Azzi Abdelmalek
on 13 Jun 2013
Then mark the answer as [accepted]
Evan
on 13 Jun 2013
In your above code, you don't pass the handles structure when you call "MyFun." Therefore, you wont be able to access your axes through the handles structure because "handles" doesn't exist in the workspace of that function. To fix this, the easiest thing to do would be to change your function to:
function [Output] = MyFun(handles,Image1,Image2)
corr = corr2(Image1,Image2);
if (corr == 1)
axes(handles.axes1)
imshow('SAME FIG.png');
else
axes(handles.axes1)
imshow('NOT SAME FIG.png');
Then, you can call it with:
Out_Fun = MyFun (handles,Image1,Image2);
Another option, I believe, would be to leave your function definition as it is but change the instances of "handles.axes1" to just "axes1."
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!