Python's h5py reads matlab. mat file Cell Method analysis

Source: Internet
Author: User

There are many ways to read the. mat file in MATLAB using Python, and there are a lot of Chinese and foreign forums.

Visible: Python reads and writes from the mat file to the H5py file package.

Detailed Address: http://blog.csdn.net/u013630349/article/details/47090299

However, when reading the Matlab file, often is not a layer. MAT is enough to solve the problem, the. mat file may be the stored cell (100*200) data, and the cell (100*200) data is divided into multiple cells. So, how to deal with such data structure, to realize the python of MATLAB This type of data read, now on the question, the following:

"Problem One"

MATLAB has Feat_name.mat file, the form of the file is as follows

Feat_name.mat<1x10Cell>  Each element is <600x5755Double  >  

First to implement a read operation to the first matrix of the Feat_name tuple, the code is implemented as follows

Myfile=h5py. File (' F:\\wfpdm\\20150702_2105\\feat_name.mat ', ' r ') data = [myfile[element[0]][:] for element in myfile[' Feat_name '] Print Data[1].shapeout: (5755,600)

Analytical

1) The for element in myfile[' Feat_name '] implements the traversal of the cell for myfile[' feat_name '];

2) myfile[element[0]] [] is understood as myfile[element], which is the current cell of the current file;

3) [myfile[element[0]][:] for element in myfile[' Feat_name '], which enables the data to be stored in the list structure;

4) data transpose 600x5755 into 5755x600, need to implement re-transpose operation;

"Question two"

MATLAB has F.mat file, the form of the file is as follows

  -->Rank<1x454Cell>-->Each element is <53x50Double>F.Mat-->Compare<1x454Cell>-->Each element is <53x50Double>

First to implement the operation of the first matrix of the rank tuple, the code is implemented as follows

f = h5py. File ("F.mat") data = [f[element[0]][:] for element in f[' rank ']]result:in:data[0].shapeout: (50L, 53L) in:data[1].shape Out: (50L, 53L)

Analytical

Here is just one more step to write the cell.name of MATLAB data. At this point, Python read Matlab data method is complete.

"Re-Reel"

There is indeed a transpose, except that the. mat file for the general array structure does not exist, but the. mat file for the cell structure exists. A re-transpose operation is required to restore the data.

See: Python reads and writes from the mat file to the H5py file package.

Detailed Address: http://blog.csdn.net/u013630349/article/details/47090299

This is the first time I completely through the Foreign Language website forum to achieve a breakthrough, until now, completed a summary of this knowledge point is still very excited. Continue the code, kk~! ~

Reference

Http://stackoverflow.com/questions/27670149/read-matlab-v7-3-file-into-python-list-of-numpy-arrays-via-h5py

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python's h5py reads matlab. mat file Cell Method analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.