How can I pass Axes (GUI) into a function
Mostrar comentarios más antiguos
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
Respuestas (2)
Azzi Abdelmalek
el 13 de Jun. de 2013
by handles
function []=yourfunction(handles,...)
2 comentarios
Shadi Al Mahallawy
el 13 de Jun. de 2013
Editada: Shadi Al Mahallawy
el 13 de Jun. de 2013
Azzi Abdelmalek
el 13 de Jun. de 2013
Then mark the answer as [accepted]
Evan
el 13 de Jun. de 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."
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!