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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:09:17+00:00 2026-05-11T16:09:17+00:00

UPDATE: This is a known bug – link requires a login to Mathworks to

  • 0

UPDATE:
This is a known bug – link requires a login to Mathworks to access it.

Summary of bug report

An instance of a MATLAB user-defined
class saved to a MAT file using
Version 7.6 (R2008a) might not load
properly if one of its property values
is an instance of a different MATLAB
class.

Briefly, Mathworks reports that a previously saved top level custom object may be loaded incorrectly (as described below) and that the error occurs on the SAVE step. So, the data is corrupted inside the MAT file.

From my experience this seems to be intermittent. In one data analysis application I wrote out of 75 MAT files 37 were saved with this corruption 🙁

Be careful with user defined objects. I added the following test on save to make sure that the data is not corrupted

save('MAT_file_name.mat');

tmp=load('MAT_file_name.mat');
if ~isa(tmp.bb,'superClass')
    msgbox({'THE FILE WAS NOT SAVED PROPERLY', ...
            ' ', ...
            ['    MAT_file_name.mat',]})
end

Orginal Question

Here I am using MATLAB 2008a. This subtle bug is fixed in MATLAB-2009a.
Anyway, the way my two classes are defined, the save/load cycle causes the variables of one class (superClass) to be loaded as variables of my second class (propClass).

Example MATLAB (r2008a) Session

>> bb=superClass;
>> whos
  Name      Size            Bytes  Class         Attributes
  bb        1x1                60  superClass              

>> save
>> clear
>> clear classes
>> load
>> whos
  Name      Size            Bytes  Class        Attributes
  bb        1x1                60  propClass       

After loading matlab.mat, the variable bb has mysteriously changed from superClass to propClass

Class: superClass

This class needs to contain an array of type propClass and here is it’s Naive definition

classdef superClass<handle
    properties(SetAccess=private)
        a = propClass.empty  % need to set this property as type propClass 
                             % otherwise the addProp method throws an error
        count=0;
    end
    methods
        function self=superClass
             %empty class definitionS
        end
        function addProp(self)
            p = propClass;
            self.count = self.count+1;
            self.a(self.count)=p;
        end
    end
end

Class: propClass

PropClass is a second class used by the super class. Its definition is not important for this bug.

Question

So, why is superClass being changed to propClass after the load operation in MATLAB-R2008a? Secondly, how can I change the definition of superClass to avoid this symptom?

Note

I ran into this symptom in a larger class I had written and narrowed down the source of the problem. I know it occurs in the MATLAB session described above but it seems that if I add an object to the property array in superClass then the problem disappears.
So, if I call superClass.addProp before saving then the strange change from superClass to propClass doesn’t occur.

  • 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-11T16:09:17+00:00Added an answer on May 11, 2026 at 4:09 pm

    That’s a strange problem! I haven’t come across anything like that, but one thing you could try first is to move the initializations of the properties to the constructor:

    classdef superClass < handle
        properties (SetAccess = private)
            a
            count
        end
        methods
            function self = superClass
                self.a = propClass.empty;
                self.count = 0;
            end
            function addProp(self)
                p = propClass;
                self.count = self.count+1;
                self.a(self.count) = p;
            end
        end
    end
    

    I’m not sure it will have any effect, but that’s the only thing I can think of to try. Hope it helps! =)

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

Sidebar

Related Questions

UPDATE 2 This is a known bug/feature with the way Ruby 1.9.2 loads files.
Update: this question, including the title, was rephrased, see history for details I know
I know I can update a single record like this - but then how
Update: This turned into a blog post, with updated links and code, over at
How do you update this? I've never seen any current team that actually checks
Duplicate of this question . update - This is not an exact duplicate. See
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Please read this question in the context of design principles, elegance, expression of
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+
As made clear in update 3 on this answer , this notation: var hash

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.