Prev: Matlab Installation error
Next: homogeneous points
From: David on 11 Feb 2010 14:32 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
From: Donn Shull on 11 Feb 2010 14:50 "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 You could check to see if inputname works for objects Donn
From: David on 12 Feb 2010 02:08 "Donn Shull" <donn.shull.no_spam(a)aetoolbox.com> wrote in message <hl1n1s$5gl$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 > > You could check to see if inputname works for objects > > Donn Thanks Donn, but unfortunately it doesn't work: >> ocp = package.OCP(0.0, 1.0, 20); >> inputname(ocp) ??? Error using ==> inputname Scalar integer value required, but value is complex Any other ideas?
From: Jan Simon on 12 Feb 2010 11:17 Dear David! > >> ocp = package.OCP(0.0, 1.0, 20); > >> inputname(ocp) > ??? Error using ==> inputname > Scalar integer value required, but value is complex Read the help of INPUTNAME. It works in functions only and replies the name of the n'th input argument in the caller - if the variable has a name at all. Anonymous variables are e.g. x(2), if x is 1:3. Good luck, Jan
From: Donn Shull on 12 Feb 2010 11:57
"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 |