Run M-file in Google Colab but got error: no such file

Run M-file in Google Colab but got error: no such file

我想在 Colab 中 运行 M 文件(Octave)。首先,我将所有文件上传到 Google 驱动器,地址如下: /content/drive/MyDrive/Colab/Corroded/hybrid/FAEICA_ANN/

然后我使用以下代码 运行 我的文件:

!apt install octave
from google.colab import drive
drive.mount('/content/drive')
import sys
import os
py_file_location = "/content/drive/MyDrive/Colab/Corroded/hybrid/FAEICA_ANN"
sys.path.append(os.path.abspath(py_file_location))
!octave -W  MainANN_FAEICA.m

但是我得到了:

error: no such file, '/content/MainANN_FAEICA.m'
error: source: error sourcing file '/content/MainANN_FAEICA.m'

虽然我添加了路径,但 Colab 无法识别该文件。

您已将该目录添加到 Python 的系统搜索路径,而不是 Octave 的搜索路径。

运行这个文件的最简单方法是将工作目录更改为文件所在的目录,然后运行文件:

os.chdir(py_file_location)
!octave -W  MainANN_FAEICA.m