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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:18:15+00:00 2026-05-27T14:18:15+00:00

let’s assume the following easy example: f = figure; plot(-10:10, (-10:10).^3, ‘*-r’); x =

  • 0

let’s assume the following easy example:

f = figure;
plot(-10:10, (-10:10).^3, '*-r');
x = 1;
y = 1;
set(f, 'ResizeFcn', {@resizeCallback2, x, y});

while 1
    [x, y, button] = ginput(1);
    if(button ~= 1)
        break;
    end

    set(f, 'ResizeFcn', {@resizeCallback2, x, y});
end

%%--------------------------
function resizeCallback2(hFig, ~, foo, bar)    
    foo
    bar
end

Is there any easier way to always pass the ACTUAL* values for x and y to the callback function instead of having to always update it in the loop?
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-27T14:18:16+00:00Added an answer on May 27, 2026 at 2:18 pm

    It looks like you are trying to store the value of a mouse click position, and then use those values as a part of the resize function (which would be called at a later time). There are a few changes that I would make.

    First, instead of the while loop, use another callback to capture the mouse click. For example, you could use the figure ButtonDownFcn call back to trigger a function which was designed to capture the mouse position into some location.

    Second, there are better ways to store the mouse position, and the right way will depend on your skill level and the needs of your program. Some of these methods of storing data are:

    1. In the arguments to another callback, like you are doing now. This is pretty painful, but it probably works. So you could keep it if it is good enough for your needs.

    2. The ‘userdata’ field in most Matlab objects. A few people have brought this up, and it will work fine. I don’t like to rely on this because I’m always afraid that some other tool will also want to use the userdata field, and the tools will overwrite data.

    3. A global variable value. I don’t like to use globals either, for the same reason I don;t like to use the userdata field. But globals are sometimes the best solution anyway. This is probably the easiest, lowest effort solution to your problem if you only have one figure at a time. (Multiple figures would drive you towards the userdata solution as the easiest solution.)

    4. Provide a handle class to store some data (i.e. x and y) and give a copy of that class to each of the two callbacks (ButtonDownFcn and ResizeFcn). This allows the two functions to pass data, without polluting anyone else’s namespace. This is my favorite solution to this sort of problem, so I’ll give it a more detailed description below.


    To execute option (4) above would need a class to store the data that looks something like this:

        classdef ApplicationData < handle
            properties (SetAccess = public, GetAccess = public)
                x = [];
                y = [];
            end
        end
    

    Note that since ApplicationData extends handle, Matlab treats it as a pass-by-reference object, which is useful to us.

    Then you can create an instance of this class, and give it to each callback function.

        dataPassing = ApplicationData;
        set(f, 'ButtonDownFcn', @(x,y) mouseClickCapture(x,y,dataPassing));
        set(f, 'ResizeFcn',     @(x,y) resizeCallback2(x,y, dataPassing));
    

    Where mouseClickCapture looks something like this:

        function mouseClickCapture(hAxis, ignored, dataPassingClass)
        mousePositionData = get(hAxis,'CurrentPoint');
        dataPassingClass.x = mousePositionData(1,1);
        dataPassingClass.y = mousePositionData(1,2);
    

    And your resizeCallback2 looks something like this:

        function resizeCallback2(h, ignored, dataPassingClass)
        %Do something here using 
        %dataPassingClass.x
        %and
        %dataPassingClass.y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say for example i have URL containing the following percent encoded character :
Let's assume my php script sends a mail to receiver@example.com using the function mail()
Let's say for example, I have the following javascript function that returns a boolean:
Let's say you create a wizard in an HTML form. One button goes back,
Let's say you have a class called Customer, which contains the following fields: UserName
Let's assume that we are building a high traffic site that will be used
Let's say there is a graph and some set of functions like: create-node ::
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's assume that a user votes for some movies in a scale of 1

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.