Error when loading .mat file with scipy.io (ValueError: Mat 4 mopt wrong format) - matlab

I'm currently trying to load a .mat file in python using scipy and the following bit of code:
from scipy import io as sio
data= "file.mat"
output= sio.loadmat(data)
However when running the command I get the error:
ValueError: Mat 4 mopt wrong format, byteswapping problem?
What does this error message mean? Is there an issue with the file I'm trying to load?
I'm quite the novice when it comes to programming so any suggestions would be greatly appreciated : ) If there is a better way to load .mat files in python I'm open to hearing those too. Thanks in advance!

I've never seen this error before, but it is produced by line 113 in scipy/scipy/io/matlab/mio4.py
def read_header(self):
''' Read and return header for variable '''
data = read_dtype(self.mat_stream, self.dtypes['header'])
name = self.mat_stream.read(int(data['namlen'])).strip(b'\x00')
if data['mopt'] < 0 or data['mopt'] > 5000:
raise ValueError('Mat 4 mopt wrong format, byteswapping problem?')
...
Normally loadmat is the right file loader, at least among the supported types:
v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.
Do you know anything about how this file was saved in MATLAB? Any format specifications such as these?

Related

Reading files frame by frame

I have a folder containing .ply files. I want to read them and plot them like an animation. Initially i am trying to read the files and plot individually using the following code:
testfiledir = 'Files\';
plyfiles = dir(fullfile(testfiledir, '*.ply'));
for k=1:length(plyfiles)
FileNames = plyfiles(k).name;
plys=pcread(FileNames);
pcshow(plys)
end
But while running the script i get the error:
Error using pcread (line 51)
File "val0.ply" does not exist.
Error in read_pcd (line 6)
plys=pcread(FileNames);
val0.ply is one my first frame which is read in the variable 'plyfiles'
Where am I making mistake?
Use a datastore it is much easier and will keep track of everything for you. E.g.
ds = fileDatastore("Files/","ReadFcn",#pcread,"FileExtensions",".ply");
then you can read the files from it using read or readall, e.g.
while hasdata(ds)
plys = read(ds);
pcshow(plys)
end
It is slightly slower than if you can make the optimal implementation, but I prefer it big-time for its ease.

Read Biopax file in matlab

How can we read Biopax file in matlab, biopax is special type of xml file. How we can retrieve information from it using matlab.
There is a BioConductor package for reading and manipulating BioPAX files in R (http://bioconductor.org/packages/release/bioc/html/paxtoolsr.html).
Check out the related tutorial on getting set up in R:
https://www.youtube.com/channel/UCWSbcyynroIp-f6O3sfz7jg
AND using PaxtoolsR:
http://bioconductor.org/packages/release/bioc/vignettes/paxtoolsr/inst/doc/using_paxtoolsr.html

Error using matlab.io.fits.openFile - cannot open FITS files

I am running a code that uses the fitsread function to open my fits movies and analyse them. It was working perfectly fine until about a week ago, when, without me doing anything, it started giving the following error whenever I try to run it:
Error using matlab.io.fits.openFile (line 48)
Unable to open file. File might be corrupt or filename might have unsupported
characters.
Error in fitsread>read_image_hdu (line 412)
fptr = fits.openFile(info.Filename);
Error in fitsread (line 125)
data = read_image_hdu(info,1,raw,pixelRegion);
I have tried manually checking the properties of such files using the fitsinfo function and nothing was wrong with the files themselves. I have also tried to re-set the default MATLAB path, delete them from the working folder and re-download them from a central University server where they were originally stored upon acquisition on a microscope, but it didn't help either. A collaborator has tried running the same code on his machine and it works well. I get this same error on both MATLAB versions R2011b and R2015b. It originally used to work on R2011b with the same files.
Thanks in advance to whoever will be able to help!

matlab read h5 file produced with pandas

I have a csv file and I have transformed it in an h5 file with pandas:
data = pd.read_csv('file.csv')
data.to_hdf('file.h5', 'table')
Now I would like to read it with matlab.
How can I do that?
I have tried
data = h5read('file.h5','/g4/lat');
but I get:
Error using h5readc
The HDF5 library encountered an error and produced the
following stack trace information:
H5G_traverse_real component not found
H5G_traverse internal path traversal failed
H5G_loc_find can't find object
H5Dopen2 not found
Error in h5read (line 58)
[data,var_class] =
h5readc(Filename,Dataset,start,count,stride);
Error in read_time_series (line 4)
data = h5read(data_path,'/g4/lat');
You need to export with format='table', see docs here.
This is can be read by various R packages and should be ok in matlab, as this is plain vanilla HDF5, which some meta-data attached (which is probably not read automatically).

error using save can't write file

I have got this really strange error in matlab. When I try to run the command
save(fullfile('filepath','filename'),'var','-v7');
I get the error message,
error using save can't write file
but when I try
save(fullfile('filepath','filename'),'var','-v7.3');
everything works fine. The the variable takes some space on the workspace, 165MB, but the I would guess that the size should not be an issue here. Does anyone know why it does not work to save in v7?
For the one that want to confirm the size of the variable, I will add the whos information,
Name Size Bytes Class Attributes
myName 1x1 173081921 struct
BR/ Patrik
EDIT
The variable I try to save is a struct with plenty of fields. I have tried to save a 3 dimensional matrix of size 800 mb, which went through without problems.
This is not an exact match to your problem, but I received the same error message when trying to save to -v6 format. Matlab is supposed to issue an error when a variable type or size is not supported:
help save
...
If any data items require features that the specified version does not support, MATLAB does not save those items and issues a warning. You cannot specify a version later than your version of MATLAB software.
Matlab's error checking seems to not be perfect, because there are certain situations (dependent on Matlab version and the particular variable type) that just fail all together with this not so helpful error message:
Error using save
Can't write file filename.mat.
For example, saving a string with certain unicode characters with the '-v6' option in Matlab r2015b in Linux produces the error, but Matlab r2016a in Windows does not. This is the output from my Matlab r2015b session:
>> A=char(double(65533))
A =
?
>> save('filename.mat','-v6','A')
Error using save
Can't write file filename.mat.
Without having your specific variable to test with, but seeing that the error messages match, I suggest removing parts of your data structure until it will save in order to isolate the variable that is causing it to fail.