> Hi,
>
> Could someone test something I'm wondering about classdef reload in MATLAB. Let's say there's a class defined as:
>
> classdef ClassA < handle
> properties
> p1 = 0;
> end
> end
>
> At the prompt, create an object of ClassA:
>
> x = ClassA()
>
> Then, without closing MATLAB, edit the classdef file and a second property, the class now looks like this:
>
> classdef ClassA < handle
> properties
> p1 = 0;
> p2 = 1;
> end
> end
>
> At the prompt, create a second object of ClassA:
>
> y = ClassA()
>
> The question is: what are the properties of x and y?
>
> A similar question occurs for methods. If the initial definition of ClassA contains a method m1. After creation of x, a second method m2 is added and another object is created. Is method m2 valid for object x? That is, does this succeeds (assuming m2 does not take any argument):
>
> x.m2()
>
> Michael.
(I used the wrong email account the first time, so I'm resending)
My first impression was that the objects were registered with the class ... but they apparently are not(?)
"clear x y" did not allow the modified class to be used. I had to "clear all" before the modified class could be used. I assume that implies that a class cannot be over-ridden once is has been loaded, unless it is cleared first.
In any event, the command you asked for and some more are below.
x = ClassA ()
x =
ClassA handle
Properties:
p1: 0
Methods, Events, Superclasses
y = ClassA ()
Warning: The class file for 'ClassA' has been changed, but the change cannot be applied because objects based on the old class file still exist. If you use those
objects, you might get unexpected results. You can use the 'clear' command to remove those objects. See 'help clear' for information on how to remove those
objects.
y =
ClassA handle
Properties:
p1: 0
Methods, Events, Superclasses
clear y
x = ClassA
Warning: The class file for 'ClassA' has been changed, but the change cannot be applied because objects based on the old class file still exist. If you use those
objects, you might get unexpected results. You can use the 'clear' command to remove those objects. See 'help clear' for information on how to remove those
objects.
x =
ClassA handle
Properties:
p1: 0
Methods, Events, Superclasses
clear x y
x = ClassA
Warning: The class file for 'ClassA' has been changed, but the change cannot be applied because objects based on the old class file still exist. If you use those
objects, you might get unexpected results. You can use the 'clear' command to remove those objects. See 'help clear' for information on how to remove those
objects.
x =
ClassA handle
Properties:
p1: 0
Methods, Events, Superclasses
>> clear all
>> x = ClassA
x =
ClassA handle
Properties:
p1: 0
p2: 0
Methods, Events, Superclasses
Ben