Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3960354
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:50:38+00:00 2026-05-20T02:50:38+00:00

I have been looking everywhere but I can’t find a site that shows how

  • 0

I have been looking everywhere but I can’t find a site that shows how to do this.
The thing I want is to be able to select an object from an axes when I click it, so that I can change its colours and stuff.

I just can’t figure out how to select a child, I can create objects but not select them.

I have this piece of code I use to create a line:

coord = ginput (2)
x = coord(:,1)
y = coord(:,2)
hline = line(x,y)

I’m not sure If i need to create the objects in an array so that I can select edit/delete them.
I believe I would need to use ButtonDownFcn, but probably I’m doing something completely wrong.

Any help would be appreciated, If I’m missing any information please let me know

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:50:39+00:00Added an answer on May 20, 2026 at 2:50 am

    It is not necessary to use ginput and extract the coordinates. This is done automatically by an built-in “listener” in the figure-window. You are correct in assuming that you can use the ButtonDownFcn property on the object (line, lineseries, or other handle graphics object).

    Try to create at simple line from (0,0) to (1,1):

    hline = line([0,1],[0,1]) %# create line, save handle in hline
    

    Then you can set the ButtonDownFcn to, for instance, a function handle to an anonymous function:

    set( ...
       hline, ...
       'ButtonDownFcn', @(handle,event)(disp(['You clicked on the line!'])) ...
    );
    

    Now try to click on the line. It should print the text in the command window.

    The function needs to be able to receive atleast two arguments: (1) the handle of the object itself (the line) and (2) an “event structure”. I believe the second argument is just empty when you use line-objects. But your function still needs to receive atleast these two arguments (even if you do not use them).

    Read more here: http://www.mathworks.com/help/techdoc/ref/line_props.html.

    You can also use your own function (a named function in a file):

    set( ...
       hline, ...
       'ButtonDownFcn', @(handle,event)(namedFunction(handle,event)) ...
    );
    

    … or you can use a struct-array if you (expectedly) have other arguments beyound those two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking everywhere but could not find a tutorial for this. I
I have been looking everywhere but can't seem to find a good solution for
I have been looking everywhere and can't find this.. I got a string and
I have been looking around for ages on this but cannot seem to find
I have been looking everywhere and tried every suggestion I could find for this
I've been looking everywhere for a solution to this problem but can't seen to
I've been looking everywhere but can't seem to find any examples/tutorials for my situation
Ive been looking everywhere for a possible solution to this but can't seem to
I have been looking everywhere on here and Google, but I still have this
Been searching everywhere and can't find a way to do this. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.