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
2013년 6월 13일
by handles
function []=yourfunction(handles,...)
댓글 수: 2
Shadi Al Mahallawy
2013년 6월 13일
편집: Shadi Al Mahallawy
2013년 6월 13일
Azzi Abdelmalek
2013년 6월 13일
Then mark the answer as [accepted]
Evan
2013년 6월 13일
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 Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!