English 中文(简体)
matlab to python: Access to thematlab cell range Value
原标题:matlab to python: get matlab cell array values

我对口腔和 p子来说是很新的,需要从马特拉布细胞阵列中用一些价值观。

I have a cell array of integers that after i execute this line of code and print the result, i get this:

a = loadmat( file.mat )
print a

{ __version__ :  1.0 ,  __header__ :  MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Wed Sep 21 15:30:15 2011 ,  juncForward_c : array([[ [[ [[ ([[30]], **[[91], [87]]**, [[3]], [[2.2455372690184494, 3.6052402625905993, 5.5884470309828833]], [[14.0, 4.0, 15.4]], [[-1, -1, 2]], [[91, 89, 93], [88, 85, 86]], [[500, 500, 5]], [[1, 2, 3]], [[11.133333333333333]], **[[4]]**, [[1]], [[1]], [[1.0], [20.365168528421695]])]]

[[ ([[30]], **[[99], [80]]**, [[3]], [[4.0376480381611373, 2.3561944901923448, 6.0857897473297058]], [[10.0, 15.4, 16.600000000000001]], [[-1, 1, 3]], [[98, 98, 100], [79, 81, 80]], [[500, 6, 33]], [[1, 2, 3]], **[[14]]**, [[2]], [[1]], [[1]], [[2.0], [6.6573267908372973]])]]

印刷版还在继续。

难道有人会向我解释如何安排手机阵列? (上述内容有多少方面?)

I then have a few questions: 1) Within this cell array, there are variables label and coordinates that are assigned to one array/cell (i dont know which is the actual term to use) -- the values in bold. I would like to write in Python to access this values. How should I go about it?

2) To test, I tried this -> juncInfoF = a.get( juncForward_c ) and when i try to print juncInfoF, it prints None . Why is that so? I am puzzled because previously when i tried this, it works. I could even do this -> print juncInfo[0][9][0][0]. but now I cannot even do any of the above.

最佳回答

参看loadmat(文档.mat ) 返回一个 。 我假定你正在使用从头开始的负荷功能?

from scipy.io import loadmat

scipy doc 仅提及负荷事项()交还字典,但我的猜测是,回归物体a>>>/code(>)在你的例子中是开放的单,在<代码>a>/code>上不再能查阅其内容,因为每年除拨打字码外还有几个原因。

为了防止这种情况,首先把所有数据复制成真正的字典,同时把这些数据输入:

mat_dict = {}
mat_dict.update(loadmat( file.mat ))

现在,您可以从<条码>查询所有关键和价值。

a = mat_dict[ juncForward_c ]
print(a.shape) # should work now

指出,只要你正在测试和确定数据内容,就是一个有效的解决办法。 在您的文字/模型/功能中,你只字眼地装上你想要的剪辑,然后在档案中明确填写:

f = loadmat( file.mat )
a = f[ juncForward_c ]
f.close()

我不知道附说明是否可行(目前还不支持这种工作),但必须加以测试,即便在装上<条码>a时出现例外情况,也应当处理关闭问题:

with loadmat( file.mat ) as f:
    a = f[ juncForward_c ]

edit: 绝食阵列后增加属性

import numpy as np

class MatArray(np.array):
    def __init__(self, filepath):
        f = loadmat(filepath)
        np.array.__init__(self, f[ juncForward_c ])
        self.version = f[ __version__ ]
        self.header = f[ __header__ ]
        f.close() 

现在,如果你想要像同肉类结构一样的阵列,你就是:

>>> a = MatArray( myfile.mat )
>>> a.header
 MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Wed Sep 21 15:30:15 2011 
>>> a.shape

etc

问题回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...