lola
lola

Reputation: 5799

define enum type

I would like to create a function that contains all text and constant. From the other .m files I access to the constants with giving the name of function variable.

For example, in Java:

 public enum MyEnum {
    COMBO("val1"),MENU_FILE("File");}
private final String label;

  /**
   * @param label
   */
  private MyEnum(final String label)
  {
    this.label = label;
  }

   @Override
  public String toString()
  {
    return this.label;
  }
}

Can I do the same with MATLAB?

Can I have a file that contains several enums?

Upvotes: 2

Views: 2050

Answers (1)

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

In the newest versions of Matlab you can:

   classdef WeekDays
       enumeration
            Sunday,Monday %You fill the rest yourself :)
       end
   end

Then, access it from another file like that:

  WeekDays.Sunday;
  • It is an .m code, pure Matlab. You need to have Matlab version 2011a or higher.
  • You don't need a type for the enums, unlike Java, Matlab is a dynamic language.

Upvotes: 5

Related Questions