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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:06:45+00:00 2026-06-05T22:06:45+00:00

Why does my Instantiate function not create a ‘Blank’ instance of That? I have

  • 0

Why does my Instantiate function not create a ‘Blank’ instance of That?

I have the following minimal class :

classdef That < handle
 properties
  This = ''
 end
 methods
  function Self = That(String)
   if exist('String','var') == 1
    Self.This = String;
   end
  end
  function Self = Instantiate(Self)
   if isempty(Self)
    Self(1,1) = That;
   end
  end
 end
end

If I run

This = That;
disp(size(This))     % 1x1
disp(isempty(This))  % False

and it’s all good, I have a ‘Blank’ instance of the class

If I run

TheOther = That.empty;
disp(size(TheOther))     % 0x0
disp(isempty(TheOther))  % True
TheOther.Instantiate;  
disp(size(TheOther))     % 0x0   - Expecting 1x1
disp(isempty(TheOther))  % True  - Expecting False

As you can see running my Instantiate doesn’t work and I can’t see why ? Surely it should replace the empty instance with a non empty, yet blank, one ?

UPDATE :

The Link from SCFrench lead to this http://www.mathworks.com/help/techdoc/matlab_oop/brd4btr.html under the heading Creating Empty Arrays, though this didn’t work either :

function Self = Instantiate(Self)
 if isempty(Self)
  Blank = That;
  Props = properties(Blank)
  for idp = 1:length(Props)
   Self(1,1).(Props{idp}) = Blank.(Props{idp});
  end
 end
end
  • 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-06-05T22:06:47+00:00Added an answer on June 5, 2026 at 10:06 pm

    Maybe you should make it a static function:

    methods (Static)
        function Self = Instantiate(Self)
            if isempty(Self)
                Self(1,1) = That;
            end
        end
    end
    

    Then:

    >> TheOther = That.empty;
    >> size(TheOther)
    ans =
         0     0
    >> isempty(TheOther)
    ans =
         1
    >> TheOther = That.Instantiate(TheOther);
    >> size(TheOther)
    ans =
         1     1
    >> isempty(TheOther)
    ans =
         0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user defined class that I want to create a public List
I have an actionscript class MyClass that extens NavigatorContent. I instantiate the class as
Does anyone have some code that will take a TimeZoneInfo field from .NET and
I am trying to use the following code, but it does not work when
I have a template class that I have made called hash . My template
Aloha, I have a custom control that I need to instantiate from within a
Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
Hey so I'm making a serialization function that takes a base class pointer 'Joint'
I have the following situation (simplified): a.h: #include <boost/serialisation/serialisation.hpp> class B; using namespace std;
I have a class that handles serialization in C#, called Serializer. It's implementation is

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.