How can I return a variable that represents a string of the variable name of an object, using a method of that object?
Here is a simple example:
classdef whatsMyName < handle methods function obj = whatsMyName() end function [ out ] = myNameIs(obj) out = inputname(1); fprintf('(1)my name is %s\n', out) end function [ out ] = orMaybeMyNameIs(obj) out = obj.myNameIs; fprintf('(2)my name is %s\n', out) end endend>> w.myNameIs;(1)my name is w>> w.orMaybeMyNameIs;(1)my name is obj(2)my name is obj
I'd like to be able to return "w" from the call inside a method.
Best Answer