[moved from c++ as matlab]