How can I pass Axes (GUI) into a function

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

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 13 Jun. 2013

2 Stimmen

by handles
function []=yourfunction(handles,...)

2 Kommentare

Shadi Al Mahallawy
Shadi Al Mahallawy am 13 Jun. 2013
Bearbeitet: Shadi Al Mahallawy am 13 Jun. 2013
Works like a charm. Thanks
Azzi Abdelmalek
Azzi Abdelmalek am 13 Jun. 2013
Then mark the answer as [accepted]

Melden Sie sich an, um zu kommentieren.

Evan
Evan am 13 Jun. 2013

0 Stimmen

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."

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 13 Jun. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by