2

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?

chappjc
  • 30,359
  • 6
  • 75
  • 132
lola
  • 5,649
  • 11
  • 49
  • 61

1 Answers1

5

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.
Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104