If we have an array of struct, like this:
s(1).a = 1;s(2).a = 2;s(3).a = 3;
and then if we get the field of this array, then the result would be like:
s.aans = 1ans = 2ans = 3
As I know, this output is comma separated list.
I want to have this behavior in my method output too, so that I can use my object just as how I use structs. Something like this:
classdef myObjectproperties myPropendmethods function this = myObject(input) %constructor
this.myProp = input; end function output = myMethod(this) % this function should return myProp as comma separated list
% when myObj array 'this' is given
% I don't know what to do here
% My best try:
% anyway the code below here obviously doesn't work...
output = {this(:).myProp} end end
and
myObj(1) = myObject('A');myObj(2) = myObject('B');myObj(3) = myObject('C'); myObj.myMethodans = Aans = Bans = C
It would be cool, isn't it?
I tried varargout, but it only outputs explicit number of nargout, so if the output argument is not specified, it will give only one output, which is varargout{1}.
Is there any good way to do this?
Best Answer