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
Christoph
  • 1,537
  • 13
  • 19
  • It would be more helpful, If u paste code snippet tried by you and error it throw. – AlokThakur Jan 22 '16 at 06:55
  • 1
    What does your file include? A script? A function? Your workspace? – Matthias W. Jan 22 '16 at 07: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') .......................... – Naseeha thahseen Jan 22 '16 at 08:55
  • But i get the following error : Traceback (most recent call last): File "test.py",line 8,in 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 – Naseeha thahseen Jan 22 '16 at 09:06
  • 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 http://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. – nkjt Jan 22 '16 at 09: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 http://stackoverflow.com/questions/3947549/what-is-the-difference-between-m-and-mat-files-in-matlab) – fernandezcuesta Jan 22 '16 at 10:35

1 Answers1

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!

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120