Search code examples
pythonpython-3.xpymatlab

opening a .mat file in python for using in matlab


I am trying to open a .MAT file the file name is MNIST.mat and it is located in following folder /home/debian/cs640 machine learning/assignment5 here is a script which I wrote following some search on internet what I want to do is open the file and save it as excel

#!/usr/bin/python3
import os
from mat4py import loadmat
os.getcwd()
mat=loadmat('/home/debian/cs640 machine learning/assignment5\MNIST.mat')
print (mat)

~

but currently I am getting error

Traceback (most recent call last): File "./script1.py", line 5, in mat=loadmat('/home/debian/cs640 machine learning/assignment5\MNIST.mat') File "/home/debian/.local/lib/python3.7/site-packages/mat4py/loadmat.py", line 417, in loadmat fd = open(filename, 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/home/debian/cs640 machine learning/assignment5\MNIST.mat'

so why is this error coming in my program?


Solution

  • You are mixing up Unix and DOS directory separators. You are using Linux, which uses Unix-style / for directory separators. Windows used the DOS-style \ for directory separators. Your file location has a mix of both. Just change:

    'assignment5\MNIST.mat'
    

    To

    'assignment5/MNIST.mat'