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 3488748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:18:32+00:00 2026-05-18T11:18:32+00:00

I have this line of code: delete_btn = uicontrol(rr_ops, ‘Style’, ‘pushbutton’, ‘String’, ‘Delete Graphic’,

  • 0

I have this line of code:

delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic', 'Position', [13 135 98 20], ...
'Callback', 'delete_graphic');

and a little bit upper this function:

function delete_graphic
global rr_list
selected = get(rr_list, 'Value');
selected
return;

why this code is not working? I really dont understand…

What do I need? I create one button and a listbox, clicking on button – deleting selected element from a listbox.

Thx for help.

PS
Always getting this error:

??? Undefined function or variable 'delete_graphic'.
??? Error while evaluating uicontrol Callback

here is all my code: http://paste.ubuntu.com/540094/ (line 185)

  • 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-18T11:18:33+00:00Added an answer on May 18, 2026 at 11:18 am

    The generally-preferred way to define a callback function is to use a function handle instead of a string. When you use a string, the code in the string is evaluated in the base workspace. This means that all the variables and functions used in the string have to exist in the base workspace when the callback is evaluated. This makes for a poor GUI design, since you don’t really want the operation of your GUI dependent on the base workspace (which the user can modify easily, thus potentially breaking your GUI).

    This also explains the error you are getting. The function delete_graphic is defined as a subfunction in your file rr_intervals.m. Subfunctions can only be called by other functions defined in the same m-file, so delete_graphic is not visible in the base workspace (where your string callback is evaluated). Using a function handle callback is a better alternative. Here’s how you would do it:

    • Change the callback of your button (line 216) from 'delete_graphic' to @delete_graphic.
    • Change the function definition of delete_graphic (line 185) to:

      function delete_graphic(hObject,eventdata)
      

      where hObject is the handle of the object issuing the callback and eventdata is optional data provided when the callback is issued.

    EDIT:

    If you want to pass other arguments to delete_graphic, you can perform the following steps:

    • Add the additional input arguments to the end of the function definition. For example:

      function delete_graphic(hObject,eventdata,argA,argB)
      
    • Use a cell array when you set the callback for your button, where the first cell contains the function handle and the subsequent cells each contain an input argument. For example:

      set(delete_btn,'Callback',{@delete_graphic,A,B});
      

      There is one caveat to this, which is that the values A and B stored in the cell array are fixed at what they are when you set the callback. If you change A or B in your code it will not change the values stored in the cell-array callback.

    If you aren’t able to use the above solution (i.e. if A and B need to change value), there are a few other options for how you can share data among a GUI’s callbacks:

    • You can rework the organization of your code to make use of nested functions. This makes it very easy to share data between callbacks. Some nice examples of using nested functions to create GUIs can be found in the MathWorks File Exchange submission GUI Examples using Nested Functions by Steven Lord.
    • You can store data in the UserData property of a uicontrol object. To access or update it, you just need the object handle.
    • You can use the functions SETAPPDATA/GETAPPDATA to attach data to a handle graphics object (i.e. uicontrol).
    • Since it appears your code was created using GUIDE, you can make use of the handles structure GUIDE creates to store data using the GUIDATA function.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this line of code for page load: if ($(input).is(':checked')) { and it
I have a greasemonkey user script with this single line of code... window.close(); but
I have this piece of code // TR Fading when deleted $('.delete').live('click', function() {
I have this line in a javascript block in a page: res = foo('<%=
I have this line in a useful Bash script that I haven't managed to
I have this line of JavaScript and the behavior I am seeing is that
I'm using GDOME.pm and in my script I have this line: my $doc =
I have this on line 56 in my environment.rb: I18n.load_path += Dir[ File.join(RAILS_ROOT, 'lib',
I have several files containing this line Release: X I want to increment X
I have a .mbm file that I copy to my device using this line

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.