Re: Enumeration and Global Variables



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
.



Relevant Pages

  • Re: Fortran or C
    ... The only C routine I would really call a string routine, ... Several routines that create strings *from* ... Although at the library level you can't truly check subscripts/sizes; ... not necessarily the result of subscript errors, ...
    (comp.lang.fortran)
  • Re: A fast way to judge an anagram
    ... To judge whether two strings are anagrams, ... You write both a reliable test routine and a fast routine. ...
    (comp.programming)
  • Re: OT. Good programming techniques (or not)...
    ... It's very easy to turn an Oroutine ... >> That is instantly Owith respect to the length of somestring. ... Pascal has counted strings. ... out unless it were deep in some oft-executed loop. ...
    (uk.comp.sys.mac)
  • Re: Translate small Perl to equivalent VB6?
    ... > be three possible routes to take; ... Convert to using strings to represent the binary values and twiddle those ... One routine (RangeToBlocks1, about 40 lines of code) pretty much JUST ...
    (microsoft.public.vb.general.discussion)
  • Changing the color of strings on the fly
    ... Using C5.5EE Ver G ... I need to change the colour of 10 pairs of strings on a screen as ... hangs. ... If I disable the routine it works fine. ...
    (comp.lang.clarion)