-1

I'm new to MATLAB and my mother language is C++. Now i'm trying to implement algorithm in MATLAB which uses balanced tree. As i know it can be done with using java.util.TreeSet. But i don't know how to provide my own comparator this tree. With next code i get parse error

classdef SitesComparator < java.util.Comparator<Site>

Also, in C++ i can just implement bool operator<(const Type& other). Can i do this in MATLAB, e.g. just implement lt(a, b) or something like this?

Yola
  • 18,496
  • 11
  • 65
  • 106

1 Answers1

1

If your comparator requires compiled Java, then you will need to write and compile it outside of Matlab, and then import it for use within Matlab.

To use compliled Java within Matlab, see: https://stackoverflow.com/a/9521010/931379

If you can construct your comparator completely using existing Java classes, you can construct it within Matlab and use it as you would within Java.

Community
  • 1
  • 1
Pursuit
  • 12,285
  • 1
  • 25
  • 41
  • In C++ i can just implement `bool operator<(const Type& other)`. Can i do something like this in MATLAB? I think it simpler than define comparator. Thanks. – Yola Jul 24 '15 at 07:18
  • And a little addition, can you provide a simplest `classdef`, only first row would be enough, i just want to see how to inherit compartor class from java interface. The main problem for me is that `Comparator` is generic class. – Yola Jul 24 '15 at 07:28