Re: Enumeration and Global Variables
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Thu, 31 Jan 2008 17:59:18 +0000 (UTC)
In article <ed240b25-6ee2-4801-8d51-58f308d04e1a@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
shapper <mdmoura@xxxxxxxxx> wrote:
For the past year I have been working much more with Object Oriented
languages such as C# and VB.NET than in Matlab.
Usually I can create an enumeration such as:
Enum Type
Open
Delete
Close
End Enum
Then call a function as follows:
MyFun(Type.Open)
So since Matlab does not support enumeration I think usually I just
need to do something like:
MyFun('Open')
right?
And make sure that the user knows what type of values MyFun accepts by
adding it to MyFun info for Help commands ...
... and maybe throw an error from inside MyFun when an invalida type
has been used.
Or is there a better way to do this?
If you have a number of options expressed as quoted strings, then
figuring out which option has been passed can end up taking a
surprisingly high amount of time if the function is called repeatedly.
For example I recently did some measurements on a function
that was being called about a million and a half times, and
each call to the function called another function that
used ismember to figure out the index of the quoted string in
a table. It turned out that that ismember() call, even though
it was only once per function call, was the bottleneck in
the computations, taking about 40% of the time required for the
overall routine -- so the routine ran about 1.7 times faster
when I eliminated that call to find the string index.
Working with strings as the options is nice for readability,
but if there happen to be a number of options, distinguishing
between the strings can end up being a performance problem
if there are a lot of calls being made.
--
"Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us." -- Ecclesiastes
.
- References:
- Enumeration and Global Variables
- From: shapper
- Re: Enumeration and Global Variables
- From: Walter Roberson
- Re: Enumeration and Global Variables
- From: shapper
- Enumeration and Global Variables
- Prev by Date: Creating a 3D Histpgram
- Next by Date: Re: 3D Histogram
- Previous by thread: Re: Enumeration and Global Variables
- Next by thread: matlabpool problem
- Index(es):
Relevant Pages
|