From: Daniel on
Thanks a ton for the posts. That's exactly what I'm looking
for. However, the call to "p = properties(this)" returns the
following error:
_______________________________________________________
??? Undefined function or method 'properties' for input
arguments of type 'stage'.

Error in ==> stage.stage>stage.copy at 120
p = properties(this);
_______________________________________________________

Is properties an automatic property of the class? Matlab
doesn't seem to know what it is.

Thanks,
Daniel
From: Douglas Schwarz on
"Daniel " <anothermathgeek+matlab(a)gmail.com> wrote in
message <g3dqfd$6sa$1(a)fred.mathworks.com>...
> Thanks a ton for the posts. That's exactly what I'm looking
> for. However, the call to "p = properties(this)" returns the
> following error:
> _______________________________________________________
> ??? Undefined function or method 'properties' for input
> arguments of type 'stage'.
>
> Error in ==> stage.stage>stage.copy at 120
> p = properties(this);
> _______________________________________________________
>
> Is properties an automatic property of the class? Matlab
> doesn't seem to know what it is.
>
> Thanks,
> Daniel

Hi Daniel,

I assumed you were using R2008a -- perhaps properties is a
new feature in that version.

Try using fieldnames instead. It should work the same way.

p = fieldnames(this);

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
From: Daniel on
Yes, I'm still in the dark ages here (R2007a). 'fieldnames'
did the trick. Thanks a ton!

From: M. on
>
> I don't see an easy way to copy hidden properties other
than by listing
> them in the copy method, e.g.,
>
> new.a_hidden = this.a_hidden;
> new.b_hidden = this.b_hidden;
>
> etc. or perhaps just building the p = properties(this)
cell array
> manually.
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

I created another method to find the hidden properties in a
class. It hasn't been rigorously tested, but it might be
useful to some, so here it is:


function hiddenProps = findHidden(this)
fid = fopen( which( class(this) ) );
if fid < 0
hiddenProps = {};
return
end
hiddenProps = {};
foundHidden = 0;

while ~feof(fid)
ln = fgetl( fid );
if ~isempty( regexpi( ln,
'\s*properties\s*\(\s*Hidden\s*\)' ) )
foundHidden = 1;
continue
end
if foundHidden == 1;
if ~isempty( regexpi( ln, '\s*end' ) )
break
end
if isempty( regexpi( ln, '\w*' ) )
continue
end
hiddenProps{end+1} = strtrim( strtok( ln, '=' ) );
hiddenProps{end} = strtrim( strtok(
hiddenProps{end}, ';' ) );
else
continue
end
end
fclose( fid );
end % END FINDHIDDEN method

From: M. on
>
> I don't see an easy way to copy hidden properties other
than by listing
> them in the copy method, e.g.,
>
> new.a_hidden = this.a_hidden;
> new.b_hidden = this.b_hidden;
>
> etc. or perhaps just building the p = properties(this)
cell array
> manually.
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

I created another method to find the hidden properties in a
class. It hasn't been rigorously tested, but it might be
useful to some, so here it is:


function hiddenProps = findHidden(this)
fid = fopen( which( class(this) ) );
if fid < 0
hiddenProps = {};
return
end
hiddenProps = {};
foundHidden = 0;

while ~feof(fid)
ln = fgetl( fid );
if ~isempty( regexpi( ln,
'\s*properties\s*\(\s*Hidden\s*\)' ) )
foundHidden = 1;
continue
end
if foundHidden == 1;
if ~isempty( regexpi( ln, '\s*end' ) )
break
end
if isempty( regexpi( ln, '\w*' ) )
continue
end
hiddenProps{end+1} = strtrim( strtok( ln, '=' ) );
hiddenProps{end} = strtrim( strtok(
hiddenProps{end}, ';' ) );
else
continue
end
end
fclose( fid );
end % END FINDHIDDEN method