execute function fil.m on my GUI ?

1 次查看(过去 30 天)
Hi everybody ,
I wrote a function called ex.m that displays a video with some specific properties Now I want that when I clic on a buttom on my GUI this video is displayed in the choosen axes , I want something like : axes(handles.axes3),ex.m;
Is that possible ?!

采纳的回答

Roberto
Roberto 2014-5-6
编辑:Roberto 2014-5-6
this creates a figure with a button that executes the function ex.m
h.figure = figure ;
h.axes = axes ;
uicontrol(h.figure,'style','pushbutton','String','Execute','Callback',@ex)
If you already have the axes created in a GUI you just have to set the current axes inside your code.
axes(handles.axes3);
imshow(I_RGB)
hold on ;
rectangle('Position',[Z,Z,s(2)-(2*Z),s(1)-(2*Z)],'EdgeColor','r','LineWidth',2 );
for k = 1:idx
rectangle('Position',boundingboxes,'EdgeColor','g','LineWidth',2 );
end
but be careful... handles.axes3 is a variable that only exists in your GUI function file this means that this variable does not exist in your ex.m file, one way to do what you want, is passing the handle variable as an argument to the function ex.m, other wise you'll get an error message, other way to accomplish this, is via nested functions, but all this depends on how your ex.m and myGUI.m functions are coded!
AGAIN IF I DON'T KNOW HOW IS YOUR CODE I CAN'T GIVE YOU A SIMPLE SOLUTION!!! JUST SIMPLE IDEAS OF HOW-TO DO IT
I'm going to try to give you an idea how to do it:
:file myGUI.m
handles.figure = figure ;
handles.axes3 = axes ;
uicontrol(handles.figure,'style','pushbutton',...
'String','Execute',...
'Callback',{@ex,handles});
:file ex.m
function argout = ex(handles)
...
...
% your code
...
...
axes(handles.axes3);
imshow(I_RGB)
hold on ;
rectangle('Position',[Z,Z,s(2)-(2*Z),s(1)-(2*Z)],'EdgeColor','r','LineWidth',2 );
for k = 1:idx
rectangle('Position',boundingboxes,'EdgeColor','g','LineWidth',2 );
end

更多回答(2 个)

Roberto
Roberto 2014-4-30
I don't know how's your code, but a simple way of doing it is as follows:
h.figure = figure ;
h.axes = axes ;
uicontrol(h.figure,'style','pushbutton','String','Execute','Callback',@ex)

lakhdhar
lakhdhar 2014-4-30
What that h mean ?! when I run your code a multiple empty figures appear !!!
To clarify my problem : ex.m is a code that read a video frame by frame to do some image processing and these are the last lines of this file (this imshow is in a for loop ):
imshow(I_RGB)
hold on
rectangle('Position',[Z,Z,s(2)-(2*Z),s(1)-(2*Z)],'EdgeColor','r','LineWidth',2 );
for k = 1:idx
rectangle('Position',boundingboxes,'EdgeColor','g','LineWidth',2 );
end
Now I want tnat I can display this video (the result) in special place on my interface
axes(handles.axes3);

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by