0
votes

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
1
It would be more helpful, If u paste code snippet tried by you and error it throw. - AlokThakur
What does your file include? A script? A function? Your workspace? - Matthias W.
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
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. - nkjt
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/…) - fernandezcuesta

1 Answers

1
votes

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!