Does MATLAB support collections or are there any 3rd party libraries that enable this?

9 Ansichten (letzte 30 Tage)
I do not think MATLAB has built in support for collections and generics as in other mature OOP languages like Java. Are there any 3rd party libraries for MATLAB that facilitate the use of generics and collections?

Antworten (1)

John
John am 3 Aug. 2014
I would like to answer my own question after doing some investigation. I could not find any answers to this in the Answers section or any comprehensive solutions in the File Exchange. But, a generous solution is provided with the MATLAB interface to Java classes. This is a great solution, and I would have expected nothing less from MathWorks because they make fantastic software.
It appears MATLAB does not ordinarily support collections (Maps are an exception) and generics but you can easily import the Java collections (java.util.*) and use what is perhaps the most mature set of collection facilities available. Java.util.* JAR should be in the static class path.
So you can use java.util.LinkedList like
a = java.util.LinkedList() %Call the constructor to create a LinkedList object
a.add(4) % Add 4 to the list
a.add(6) % Add 6 to the list
a.get(0) %Returns 4
But apparently you can do some things that might make those looking for type safe collections cringe. You can do this:
a = java.util.LinkedList();
a.add(3) % Add 3 to the list
a.add('4') % Add the char
Perhaps there is way to make MATLAB's Java interface allow for type safety. That is the new question!

Kategorien

Mehr zu External Language Interfaces finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by