0

I am on a project on machine learning. trained the data in matlab R2015a and obtained a file abc.m . I get the expected result from matlab file while giving input from the matlab command window. i have developed the interface in pyqt5 and got the file in python . Want to import .m file to python for usage.

have Anaconda 2.4.1 installed on my computer with python 3.5. working on Windows 8.1

Can anyone help ? totally stuck with the project.

My code is as follows :

import scipy.io as sio
import numpy as np

from sklearn import preprocessing

ab = sio.loadmat('latest.m')
......

But i get the following error :

Traceback (most recent call last):
File "test.py",line 8,in <module>
 ab = sio.loadmat('latest.m')
 File "C:\anaconda\Lib\site-packages\scipy\io\matlab\mio.py",line 58,in mat_reader_factory
 mjv,mnv = get_matfile_version(byte_stream)
 File "C:\anaconda\Lib\site-packages\scipy\io\matlab\miobase.py",line 241,in get_matfile_version
 raise ValueError('Unknown mat file type,version %s,%s' % ret)
 ValueError: Unknown mat file type,version 111,114
6
  • It would be more helpful, If u paste code snippet tried by you and error it throw. Commented Jan 22, 2016 at 6:55
  • 1
    What does your file include? A script? A function? Your workspace? Commented Jan 22, 2016 at 7:26
  • my matlab file is 'latest.m' . python code : import scipy.io as sio import numpy as np from sklearn import preprocessing ab = sio.loadmat('latest.m') .......................... Commented Jan 22, 2016 at 8:55
  • 1
    Press 'edit' above (the link directly under your question text) and put your code into your question. You should format it as code. If you don't know how, see stackoverflow.com/help/formatting . Code posted in comments is pretty much unreadable, and additional information that should go in your question should not be posted in comments. Commented Jan 22, 2016 at 9:20
  • 1
    Check first from matlab if you can load the file (m = matfile(latest.m)). Maybe you're not trying to load a valid mat file but the code (.m extension, see stackoverflow.com/questions/3947549/…) Commented Jan 22, 2016 at 10:35

1 Answer 1

1

loadmat loads a MATLAB data file, e.g. the result of some code. MATLAB data files have .mat extension.

Loading a .m file means loading a bunch of text that doesnt mean anything without a MATLAB interpreter! What you want is to load a .mat file, a file containing matrices, strings or whatever it has been saved there.

EDIT I have just seen @valtuarte 's link to What is the difference between .m and .mat files in MATLAB . Have a check!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.