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

  • Home
  • SEARCH
  • 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 842683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:00:08+00:00 2026-05-15T06:00:08+00:00

I have an object-oriented MATLAB app that needs a GUI, and I’d like to

  • 0

I have an object-oriented MATLAB app that needs a GUI, and I’d like to use GUIDE for the layout (at least). I’ve tried the manual way, and doing the control positioning is just too painful.

I’ve noticed that GUIDE is very much procedurally-oriented; it generates M-files that assume they are run from the path and aren’t associated with any classes or objects.

Has anyone had experience trying to use GUIDE in an object-oriented way? If it’s straightforward, I’d like to do automatic code generation as well, but I’m willing to let GUIDE just generate the .fig file and write the code myself.

  • 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-15T06:00:09+00:00Added an answer on May 15, 2026 at 6:00 am

    When you create a gui with guide, for every button/textbox/graph etc. you put on the pane, it automatically generates the shells for the necessary callbacks, so all you have to do is fill in the code. If you change the name of the widgets (their “tags”) or add or delete them, it updates your m-file for you, which is handy.

    You can associate your gui with objects; the autogenerated m-file has a function outline that looks like this

    function YourGUIName_OpeningFcn(hObject, eventdata, handles, varargin)
    

    you can require that someone pass your gui an object or objects through the varargin. The canonical matlab way to do this is to pass parameter name/value pairs, so the call from the command line would look like

    YourGuiName('importantobject', object1);
    

    but you could also (especially if there is just one unique argument) assume varargin{1} is a specific parameter, varargin{2} is a second, and so on

    In this case, the call from the command line would be

    YourGuiName(object1);
    

    In your openingfcn, you would then add a line like

    if (length(varargin) < 1) || ~isa(varargin{1}, 'importantObjectType')
         error ('you must pass an importantobject to YourGuiName, see help');
    end
    myimportantobject = varargin{1}
    

    You now have a choice to make. The canonically correct way to store data in your gui is to put it in the handles structure and then store it with guidata, as in

    handles.myobject = varargin{1};
    guidata(hObject, handles); %this is just boilerplate 
    

    The boilerplate is necessary because, despite its name, handles does not subclass Handle, and is passed by value, not reference. the guidata command sticks handles somewhere associated with the gui figure so you can get it in subsequent callbacks.

    The problem with this approach is that when you put a large object in handles, it makes the guidata command take forever. This is true even though MATLAB is not supposed to copy data when passing by value unless absolutely necessary, and it is even true if your object is a Handle, which takes like 4 bytes to pass back and forth. Don’t ask me why, but I suspect it has something to do with memory management & garbage collection.

    If your gui is taking a while to execute commands, and you use profile and see it hanging on the guidata command, you should just declare your object to be a global and deal with it that way

    global YOURGUI_object;  %it's not my fault; blame MATLAB
    YOURGUI_object = varargin{1};
    

    Then you can just have all your callbacks execute whatever method of YOURGUI_object they need.

    Good luck.

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

Sidebar

Related Questions

I have: existing object oriented native code API (non GUI) GUI application that works
I think I read somewhere that some modules only have object oriented interfaces (
I have a need to create a library of Object Oriented PHP code that
Assuming I have to use C (no C++ or object oriented compilers) and I
I have always heard that C++ is not Object Oriented but rather C with
I am new to object-oriented JavaScript. Currently, I have an object that I need
I have some Result classes that represent flat results in an object oriented fashion.
I'm new to object oriented javascript. I have a set up method that I
I have an object oriented framework that uses a page design, where each page
i am making an object-oriented app in coldfusion, and so i have really broken

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.