Equivalent C ++ std :: set in Matlab

How can I define set in Matlab, which has the following properties:

  • Unique elements
  • Effective search
  • Ordered

Perhaps there is no built-in container. So, how can I combine some things to get the above things the same as std::set in C ++?

+6
source share
1 answer

You can use Java HashSet as follows:

 >> x = java.util.HashSet; >> x.add(1); >> x.add(2); >> x.contains(1) ans = 1 >> x.contains(3) ans = 0 >> x x = [2.0, 1.0] 

The comments stated that the HashSet is not streamlined. Which is absolutely true. To blame! Instead, you can use TreeSet, which is ordered:

 >> x = java.util.TreeSet; >> x.add(1); >> x.add(3); >> x.add(2); >> x x = [1.0, 2.0, 3.0] 
+7
source

All Articles