I have created a class function named "testclass" that creates class object with differently ordered field names based on the input argument 'opt'. The code is as follows:
function cls = testclass(opt)if(opt) cls.a = 1; cls.b = 2; cls.c = 'hello';else cls.c = 'hello'; cls.b = 2; cls.a = 1;endcls=class(cls,'testclass');
This function is placed in a folder named "@testclass".
Now, I execute the following statement:
c1 = testclass(1)
The output is given as:
c1 = testclass object: 1-by-1
Then if I execute the following command,
c2 = testclass(0)
I receive the following error:
??? Error using ==> class Field names and parent classes for class testclass cannot be changed without clear classes. Error in ==> testclass.testclass at 14 cls=class(cls,'testclass');
I did not change the field names or the number of fields in the class. All I changed was the order of the fields.
Best Answer