NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

MatlabCompat.jl: helping Julia understand Your Matlab/Octave Code

Vardan Andriasyan, Yauhen Yakimovich, Artur YakimovicharXiv 2017

Abstract

Transitioning legacy research code from established environments like MATLAB to modern, high-performance languages like Julia often presents a significant technical barrier. This paper introduces MatlabCompat.jl, a Julia library designed to facilitate this migration through a "transliterate and refine" workflow. By providing automated syntax transformation tools and a library of MATLAB-like function wrappers, MatlabCompat.jl enables researchers to modernize their computational pipelines without the need for a complete manual rewrite, effectively addressing the "Two-Language Problem" in scientific research.

Introduction

For decades, MATLAB and its open-source counterpart, GNU Octave, have served as the standard for scientific computing. However, as research datasets scale, these interpreted languages frequently encounter performance bottlenecks, particularly in non-vectorized code—a challenge often referred to as the "Two-Language Problem." While Julia was developed to provide C-like performance with high-level syntax, the prospect of porting thousands of lines of legacy code remains daunting for many researchers. Differences in syntax (e.g., string delimiters) and core function naming conventions (e.g., max() vs. maximum()) create friction that hinders adoption. MatlabCompat.jl was developed to lower this barrier by providing a transitional framework for code migration.

Methodology: The "Transliterate and Refine" Strategy

Rather than attempting a full, automated semantic conversion—which is often prone to error in complex scientific scripts—MatlabCompat.jl employs a two-stage strategy designed to get code running quickly in the Julia environment.

1. Automated Syntax Transformation

The toolkit includes the rossetta() function, a parsing tool that performs basic syntax transformations on .m files. This includes converting single quotes to double quotes and adjusting other syntactic nuances to produce a .jl file that is immediately interpretable by the Julia compiler.

2. The Compatibility Library

To handle functional differences, the authors developed a suite of Julia modules—including MathTools, StringTools, and ImageTools—that provide aliases or re-implementations of familiar MATLAB functions. To prevent namespace pollution, these are implemented using a modular inclusion model. For example, a user can explicitly call MatlabCompat.MathTools.max() to maintain legacy behavior where Julia’s native max() might differ, allowing for a gradual transition to native Julia syntax.

Experimental Validation

The efficacy of MatlabCompat.jl was validated using both standard algorithmic benchmarks and real-world biological image analysis use cases:

  • A549 Human Lung Carcinoma Micrographs: Automated nuclei counting was performed on images of cultured cells stained with Hoechst 33342 dye.
  • C. elegans Infection Dataset: High-throughput screening data from a study by Moy et al. (2009) was used to quantify "death signals" via SYTOX Orange fluorescence in roundworms infected with Enterococcus faecalis.
  • Algorithmic Benchmarks: Standard tests, including Fibonacci recursion, Mandelbrot set generation, and Quicksort, were used to compare execution speeds between the two environments.

Key Results and Discussion

Performance Dynamics

The results highlight a critical distinction between vectorized and non-vectorized code. In tests of Fibonacci recursion—a classic measure of loop efficiency—Julia outperformed MATLAB by three orders of magnitude. This demonstrates Julia's primary advantage: eliminating the performance penalty for iterative logic that typically forces MATLAB users to rely on complex vectorization.

However, the authors include a "word of caution" regarding highly optimized vectorized code. In the "Janus" image analysis benchmark, MATLAB R2014a performed slightly faster than Julia 0.3.10 (approximately 0.29x the execution time). This suggests that if a legacy codebase already leverages MATLAB’s highly optimized internal kernels effectively, porting alone may not yield immediate speedups without further refactoring into native Julia idioms.

Functional Parity

In the C. elegans use case, the automatically translated Julia code produced quantification results identical to the original MATLAB scripts. This confirms that the rossetta() conversion and the compatibility wrappers maintain scientific integrity during the migration process.

Conclusion and Future Work

MatlabCompat.jl provides a pragmatic pathway for researchers to migrate from MATLAB to Julia. By prioritizing a "minimal target-invasive" approach, it allows scientists to maintain their research momentum while gradually adopting Julia’s advanced features like multiple dispatch and native dataframes.

At the time of writing, the library is in an early stage, with a heavy emphasis on image processing. Future development aims to expand coverage to specialized toolboxes (such as Control Systems and Signal Processing) through a community-driven GitHub organization. While currently a one-way migration tool, MatlabCompat.jl represents a significant step toward unifying the scientific computing community under a high-performance, open-source standard.

Summary updated

BibTeX
@misc{andriasyan2017matlabcompat,
  author = {Vardan Andriasyan and Yauhen Yakimovich and Artur Yakimovich},
  title = {{MatlabCompat.jl: helping Julia understand Your Matlab/Octave Code}},
  year = {2017},
  eprint = {1701.02220},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1701.02220},
}
Figure