pythonmatlaboctavegoogle-colaboratoryoct2py

"exists_or_mkdir" undefined after using Oct2Py on *.m (Matlab) file in Google Colab


I've been trying to figure out how to run Matlab files in Google Colab.

I've installed Octave (apt install Octave) into my Colab. But trying to run my .m file with !octave -W make_video.m then just returned

parse error near line 91 of file /content/drive/testing/catdeform/code/util/figure_code/make_video.m

  nested functions not implemented in this context

>>> function [shape] = load_shape(res_dir, anchor_coords, anchors)
           ^

error: source: error sourcing file '/content/drive/testing/catdeform/code/util/figure_code/make_video.m'make_video.m'

So then I did !pip3 install oct2py

and went into the directory the .m file is in and did:

from oct2py import Oct2Py 
oc = Oct2Py
oc.make_video

And got output "make_video" Octave function

Then I did !octave -W make_video.m again and got:

error: 'exists_or_mkdir' undefined near line 51 column 1
error: called from
    make_video at line 51 column 1

What might I be doing wrong? Maybe there is a way better approach to take than trying to even use Octave/oct2py for running matlab files in Google Colab?


Solution

  • There are several things to say here, but let's start with the obvious.

    It should be

    oc = Oct2Py()
    

    not

    oc = Oct2Py
    

    The first creates an Oct2Py instance (which is obviously what you want), the second is simply creating an alias to the Oct2Py class definition.

    Note that the oct2py package provides an already instantiated singleton instance for you to use, oct2py.octave. So you could simply do:

    from oct2py import octave
    octave.make_video
    

    Having said that, let's address some of the other stuff.