简体   繁体   中英

“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?

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.

  • Oct2Py does not run "matlab" scripts. It runs "octave" scripts. This is not a trivial point. While there is large overlap between the two, they are not 100% compatible. If you want to be sure that your 'matlab' script is compatible with 'octave', try running it on a local octave installation first.

  • Case in point: The error you got is an octave error, not a Colab error. Earlier versions of octave did not have full support for nested functions in all the contexts that matlab allows. Therefore you got this error. Apparently this should no longer be an issue in the latest octave release, which is 6.1.0. However, your 'kernel' may rely on an older octave. Is it possible to point Colab to an Octave 6.1.0 kernel/instance somehow?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM