Change image after mouse over?

2 ビュー (過去 30 日間)
Colin
Colin 2011 年 7 月 22 日
I have a GUI set up at the moment with one component being an axes that is holding an image. What I want is when the user mouses over the axes/image the image changes to something else.
How would I go about doing something like this using the WindowButtonMotionFcn?
First I am not sure how I make this function work with an axes, and second I do not know where to place it with the code.
All the sources I have read do not use it the in the GUIDE GUI .m file, and instead in their own functions.
In the GUIDE GUI .m there doesn't seem to be any place to constantly check to see whether or not a mouse over has occurred.
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 7 月 23 日
I am really not fond of having someone delete their previous question after I have answered it -- and all their prior questions too.
I am sitting this one out, as I have no interest in putting even more time in to a solution that will probably just be deleted anyhow.

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

採用された回答

Chirag Gupta
Chirag Gupta 2011 年 7 月 22 日
You cannot have WindowsButtonMotionFcn for the axes, but you can have it for the figure. Just select the GUI figure, right click-> view Callbacks and choose WindowsButtonMotionFcn. This should create one for you in the MATLAB file.
I had sample code in there as:
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[posx, posy ]= get(hObject,'CurrentPoint');
% Write your code to Check to see if the mouse is over the axes
if (checkoveraxes...)
plot(handles.axes1,rand(10)); % Change image, here i'm just plotting
end
  2 件のコメント
Colin
Colin 2011 年 7 月 22 日
>% Write your code to Check to see if the mouse is over the axes
>if (checkoveraxes...)
> plot(handles.axes1,rand(10)); % Change image, here i'm just >plotting
>end
Ok so this part is something I write. So far Posx and Poy are tracking where the mouse is... then I would say.. if Posx and Poy are within 'such and such' bounds (AKA where axes is) then do plot (or in my case change figure).
Colin
Colin 2011 年 7 月 22 日
Ok I have this so far
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[posx, posy ] = get(hObject,'CurrentPoint');
%Display to check to see if the position is working
posx = num2str(posx);
posy = num2str(posy);
set(handles.Xpos,'String',posx);
set(handles.Tpos,'String',posy);
%If mouse over then update the immage
if (295 > posx > 169 && 122 > posy > 71)
axes(handles.axes1);
imshow('exp.png')
end
But the display isn't even updating

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by