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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:56:41+00:00 2026-05-28T02:56:41+00:00

How to dynamically create a class from its content? In fact I’ve create a

  • 0

How to dynamically create a class from its content?

In fact I’ve create a kind of Matlab engine classes instantiation and execution, in which I can list all class files (*.m) in a directory, instantiate them (with ‘eval(clasnname)’) and use theses objects.

Now I want to change the file content of theses files “on the fly”, and then, instantiate them and use these new objects.

So I’ve written a function to read the content of file into a string, replace/add some contents into this string and… I don’t know how to create an object (instance of a class) from this string (which contains ‘classdef myClass < myMotherClass \n … end’). (I know that I can create a new file on my filesystem with this string content and then use eval(…) as I’ve already done, but I try to do this without create new physical file).

Does someone know how to do it?

  • 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-28T02:56:42+00:00Added an answer on May 28, 2026 at 2:56 am

    I don’t think that this is possible in MATLAB, unlike in a pure object-oriented programming language like Ruby. If it were, then there would be some way of building a meta.class object, but there’s not.

    I think that writing a classdef file is your only option. You may need to programmatically call rehash in order to get it to load the new definition and if there are existing objects using the old definition, then it won’t load the new definition at all until you clear everything.

    I suppose the real question is “Why do you need to do this?”

    Aside: Use feval rather than eval to create instances of your new class.

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

Sidebar

Related Questions

I have been curious about dynamically create class at runtime in C# and stumbled
Is there a way to dynamically and conditionally create a class definition in PHP,
Ladies & Gentlemen, Short Version: Trying to dynamically create a Spine Model Class. Basically
I have a rather unique class that allows its child classes to declare virtual
I am trying to dynamically create module level functions from the methods in a
I'm defining my own AR class in Rails that will include dynamically created instance
Is it possible to dynamically create and modify images on a per pixel level
I need to dynamically create a Video object in ActionScript 2 and add it
I would like to dynamically create a minimal transparent bar graph to display over
When I dynamically create a Datagrid and add in a new buttoncolumn how do

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.