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

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 13 日

2 投票

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

2 件のコメント

Shadi Al Mahallawy
Shadi Al Mahallawy 2013 年 6 月 13 日
編集済み: Shadi Al Mahallawy 2013 年 6 月 13 日
Works like a charm. Thanks
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 13 日
Then mark the answer as [accepted]

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

Evan
Evan 2013 年 6 月 13 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Properties についてさらに検索

製品

質問済み:

2013 年 6 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by