Change Mouse/ Cursor appearance in ginput

조회 수: 37 (최근 30일)
Max Müller
Max Müller 2014년 9월 25일
편집: Johannes Korsawe 2023년 6월 9일
Simple Question:
is it possible to Change the Cursor appearance in ginput ?
Explanation:
If you use the ginput command, you will get a Crosshair as Cursor.Is it possible to get something like a grapping hand or ..... If you open a new figure and look into the menu bar, u will find a Pointer,a magnifier and a hand. Can i get these Objects for ginput ?

답변 (3개)

Adam
Adam 2014년 9월 25일
편집: Adam 2014년 9월 25일
As far as I know you cannot set pointer type for ginput.
might be useful to you. It is something we (the team I work in) downloaded a while back for use in place of ginput for pretty much the same reason as you. It allows you to specify pointer type.
It is a horribly named function but it does a good job.
You can use any pointer type that you can set on a fig. These can be found by just typing:
set( gcf, 'pointer' )
on any figure you have. Any option in there should be usable so far as I know and looking at the code as that is the property it sets with the pointer string you pass in.
  댓글 수: 3
Adam
Adam 2014년 9월 25일
편집: Adam 2014년 9월 25일
[xVal, yVal, button] = myginput( 1, 'crosshair' );
is how I used it in one of our programs so it appears to git the same syntax. The help at the top of the file also confirms syntax is identical to ginput except for the final extra argument.
It is a fileexchange download so you can simply edit the file and rename it if you want, taking note of any license requirements it has. In this case there appears to be no license file with it at all so you can do whatever you want with it for your own usage.
Obviously you could also simply create a wrapper function with a name you prefer as e.g.
function [x,y,button] = myBetterName( args )
[x,y,button] = myginput( args );
where 'args' would obviously be replaced by whatever inputs it expects. Then you can just call your own named wrapper function.
Sean de Wolski
Sean de Wolski 2014년 9월 25일
@Adam: Being covered by the BSD license explicitly allows you to modify and redistribute.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Not having a license means... That's why we almost never pick non-BSD files for pick of the week.

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2014년 9월 25일
What are you trying to do?
I typically avoid ginput and would recommend using an impoint (Image Processing Tbx req'd) instead.
  댓글 수: 1
Max Müller
Max Müller 2014년 9월 25일
first: I am only an intern so my Supervisor has to download this, cause some how i cant.
second: thanks a lot for the help
third: I am trying to get the x and y Coordinates of a Plot with ginput in a while fcn, which is close when button > 1.

댓글을 달려면 로그인하십시오.


Johannes Korsawe
Johannes Korsawe 2023년 6월 9일
편집: Johannes Korsawe 2023년 6월 9일
This can be done very easily:
  1. Use a local copy of Mathworks' original function ginput.m which has precedence in your Matlab path.
  2. Adapt this copy to take two arguments: "Number of ginput points" and "pointersymbol". Make sure that the pointersymbol is set to [] if nargin==1.
  3. Add pointersymbol as a second argument to the call and definition of the local funtion setupFcn inside ginput.
  4. use the following code iside the local function setupFcn before the setup of the "ginput"-pointer:
try
%Setup custom pointer
set(gcf, 'Pointer', pointerSymbol);
%Define the following entities, s.t. the restoreFcn has something to delete
initialState.CrossHair = createCrossHair(fig);
initialState.MouseListener = createCrossHair(fig);
catch
%Setup empty pointer
...
end
Done. You can call the by ginput(5) to show the Mathworks' intended pointer behavior or use e.g. ginput(5, 'crosshair') to prescribe a custom pointer as a a figure property.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by