Thread Subject: setter function in OOP

Subject: setter function in OOP

From: John Kreuder

Date: 2 Nov, 2009 20:48:02

Message: 1 of 1

I want to use a setter function in the following manner:

set(C,C.pn,C.pv)
C is an object that inherits handle and hgsetget, C.pn is a 1x3 cell array of strings referencing properties of C and C.pv is an array of values to which i would like to set the properties in C.pn. Parameters, pv and pn are public properties of C.

here's the kicker, the property of C that I am referencing with the strings is a structure and the values I am trying to set are fields of that structure. MATLAB gives a 'property does not exist' error when the command executes. Here are some more details:

parameters is a public property of object C
C.pn = {'parameters.sub1.sub2.a' 'parameters.sub1.sub2.b','parameters.sub1.d'}
C.pv = [1,3,pi]

Again, the error is occurring because the set function does not recognize that parameters is a structure with multiple substructures and so it tries to set a field named C.parameters.sub1.sub2.a equal to 1 while the public property in C is just straight up "parameters".

How can I adjust this update relationship to recognize the subfields?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
oop setter func... Hasan Yousuf 2 Nov, 2009 16:02:52
oop setter func... John Kreuder 2 Nov, 2009 15:49:02
rssFeed for this Thread

Contact us at files@mathworks.com