From: Hugo on
Hi. I would like to add commands to my class definition in the same way as "plot" can does... for example, consider this example:

plot(X,Y,'o','Color','red','LineWidth',2)

To me:
- 'o' is a command that does not accept arguments; and,
- 'Color' and 'LineWidth' are commands that accept/require an argument to be defined next.



Now, please consider this class definition...


classdef RSpectrum
properties
accelerogramPath
accelerationMethod='average';
numPoints=200;
Tf=5;
zeta=0.05;
end

properties (Dependent=true, SetAccess=private)
spectrum
end


methods
function obj=RSpectrum(accelerogramPath,varargin)
...
end

...
end

....
end



I would like to add the following commands (all of them require an argument to be defined next):
1. 'accelerationMethod'
2. 'numPoints'
3. 'Tf'
4. 'zeta'

so I can do this, for example,

s=RSpectrum('acc.at2','zeta',0.025,'numPoints',500);


I actually have a workable version of this. However, I would like to know if MATLAB can handle this kind of definitions out-of-box.


Any help/comment regarding this subject will be greatly appreciated.

Many thanks in advance!

Hugo.
From: Steven Lord on

"Hugo " <hresquiveloa(a)gmail.com> wrote in message
news:hvmfkr$8o2$1(a)fred.mathworks.com...
> Hi. I would like to add commands to my class definition in the same way as
> "plot" can does... for example, consider this example:
>
> plot(X,Y,'o','Color','red','LineWidth',2)
>
> To me:
> - 'o' is a command that does not accept arguments; and,
> - 'Color' and 'LineWidth' are commands that accept/require an argument to
> be defined next.

*snip*

> I would like to add the following commands (all of them require an
> argument to be defined next):

These are not "commands" -- these are property names. You're looking for
the ability to use property name/value pairs to define the properties of
your object when you construct it.

> 1. 'accelerationMethod'
> 2. 'numPoints'
> 3. 'Tf'
> 4. 'zeta'
>
> so I can do this, for example,
>
> s=RSpectrum('acc.at2','zeta',0.025,'numPoints',500);
>
>
> I actually have a workable version of this. However, I would like to know
> if MATLAB can handle this kind of definitions out-of-box.

Look at the INPUTPARSER object and the VALIDATESTRING and VALIDATEATTRIBUTES
functions.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Hugo on
Steve,

Thank you!
 | 
Pages: 1
Prev: text annotate graphs
Next: demo files in Webinars