Prev: Matlab Installation error
Next: homogeneous points
From: David on 12 Feb 2010 12:10 "Donn Shull" <donn.shull.no_spam(a)aetoolbox.com> wrote in message <hl419j$dsf$1(a)fred.mathworks.com>... > "David " <david.removethispart.ariens(a)esat.kuleuven.be> wrote in message <hl1lvi$nck$1(a)fred.mathworks.com>... > > Dear all, > > > > I'm writing an object oriented piece of software in Matlab and I am looking for the following functionallity: > > > > x = package.classobj1; > > y = package.classobj2; > > > > package.testfunction(x,y); > > > > In the constructor of testfunction I save obj.var1=x, obj.var2=y but I also want to know the string name of these 2 variables. Eg: I want to know the string "x" and the string "y". > > > > This would result in something like: > > obj.var1name = SOMEFUNCTION(x); > > obj.var2name = SOMEFUNCTION(y); > > > > Does anyone know whether it is possible in Matlab to get this info? > > > > Thanks > > Hi David, > > Is this what you are looking for? > > classdef testfunction > properties > var1; > var1name; > var2; > var2name; > end > methods > function obj = testfunction(in1, in2) > obj.var1 = in1; > obj.var1name = inputname(1); > obj.var2 = in2; > obj.var2name = inputname(2); > end > end > end > > >> value1 = 32 > > value1 = > > 32 > > >> value2 = 45 > > value2 = > > 45 > > >> object = testfunction(value1, value2) > > object = > > testfunction > > Properties: > var1: 32 > var1name: 'value1' > var2: 45 > var2name: 'value2' > > Methods > > >> > > Good Luck, > > Donn That's exactly it! Thanks, Donn!
From: Loren Shure on 12 Feb 2010 13:07
In article <hl419j$dsf$1(a)fred.mathworks.com>, donn.shull.no_spam(a)aetoolbox.com says... > "David " <david.removethispart.ariens(a)esat.kuleuven.be> wrote in message <hl1lvi$nck$1(a)fred.mathworks.com>... > > Dear all, > > > > I'm writing an object oriented piece of software in Matlab and I am looking for the following functionallity: > > > > x = package.classobj1; > > y = package.classobj2; > > > > package.testfunction(x,y); > > > > In the constructor of testfunction I save obj.var1=x, obj.var2=y but I also want to know the string name of these 2 variables. Eg: I want to know the string "x" and the string "y". > > > > This would result in something like: > > obj.var1name = SOMEFUNCTION(x); > > obj.var2name = SOMEFUNCTION(y); > > > > Does anyone know whether it is possible in Matlab to get this info? > > > > Thanks > > Hi David, > > Is this what you are looking for? > > classdef testfunction > properties > var1; > var1name; > var2; > var2name; > end > methods > function obj = testfunction(in1, in2) > obj.var1 = in1; > obj.var1name = inputname(1); > obj.var2 = in2; > obj.var2name = inputname(2); > end > end > end > > >> value1 = 32 > > value1 = > > 32 > > >> value2 = 45 > > value2 = > > 45 > > >> object = testfunction(value1, value2) > > object = > > testfunction > > Properties: > var1: 32 > var1name: 'value1' > var2: 45 > var2name: 'value2' > > Methods > > >> > > Good Luck, > > Donn > just realize that the varname properties could end up with empty strings if a temporary expression was used as input by the caller. -- Loren http://blogs.mathworks.com/loren http://matlabwiki.mathworks.com/MATLAB_FAQ |