From: Doug Schwarz on
In article <hmbf6s$hvg$1(a)fred.mathworks.com>,
"Vincent Huang" <huangwen(a)hotmail.com> wrote:

> Hi,
>
> Thank you for the reply.
>
> fem0.sol.u(17:120:28817,11)=100;
> > ??? Access to an object's fields is only permitted within its methods.
>
> I am using COMSOL with Matlab for my simulation project and the solution
> object is generated by COMSOL (femsolver.m).
>
> May I have an example of making a method to access the private property and
> change the original object?
>
> regards,
>
> Vincent

[snip]

I have never used COMSOL and I'm not going to read all that
documentation to figure it out.

However, I can show you a simple example of how to access a private
property of a class:

class myclass
properties (Access = private)
secret = 1;
end
methods
function s = getsecret(obj)
s = obj.secret;
end
end
end


Then,

myobj = myclass;
the_secret = myobj.getsecret

should return 1. (Untested, but should work.)

The methods of the class can access secret, but you can't access it
directly with

myobj.secret


I suggest you write the COMSOL people for any additional help with that.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
From: Vincent Huang on
Hi,
thanks for your code.

i can access the object but I still can't the change the values stored inside the orignal private object.

regards,

Vincent
From: Vincent Huang on
....
From: Steven Lord on

"Doug Schwarz" <see(a)sig.for.address.edu> wrote in message
news:see-6042B1.10220327022010(a)news.frontiernet.net...

*snip*

> If you just want to peek at the contents of an object while working at
> the command line you can use struct:
>
> obj = myclass;
> s = struct(obj);
>
> It will expose everything (I think), but you won't be able to change the
> original object.

You should receive a warning if you try to do that on an object defined in a
CLASSDEF file if the object hasn't defined a struct method to control how it
is to be converted into a struct.

If you're looking for information about the structure of an object whose
definition is stored in a CLASSDEF file, use the METACLASS or ? interfaces.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/br4iuh2.html

Use METACLASS on an instance of the object or ? on the name of the object.
For example:

>> M = containers.Map({'Massachusetts'}, {'Boston'});
>> MC = metaclass(M);
>> property1 = MC.Properties{1}
>> MC2 = ?containers.Map;
>> MC2.Properties{1}

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Steven Lord on

"Vincent Huang" <huangwen(a)hotmail.com> wrote in message
news:hm9mho$r5o$1(a)fred.mathworks.com...
> "Vincent Huang" <huangwen(a)hotmail.com> wrote in message
> <hm8p2k$qlk$1(a)fred.mathworks.com>...
>> Hi all,
>>
>> I am looking for help on making my object's field public in matlab
>>
>> fem0.sol.u(17:120:28817,11)=100;
>> ??? Access to an object's fields is only permitted within its methods.
>>
>> Please share your expertise.

If you have control over the definition of the class, change its GetAccess,
SetAccess, or Access attributes of the appropriate properties, clear all
instances of the object from memory, clear the class definition itself from
memory, and then create a new instance (which will use the modified class
definition.)

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brjjwby.html

If you don't have control over the definition of the class, ask the person
or persons that do to modify the class.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ