Created
September 3, 2013 06:34
-
-
Save JimHokanson/6420348 to your computer and use it in GitHub Desktop.
A simple example trying to walk through dereferencing of a Matlab structure array in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ViewWormMovement | |
import matplotlib.pyplot as plt | |
import h5py | |
file_path = u'F:/worm_data/segworm_data/features/798 JU258 on food R_2010_11_25__16_34_17___1___9_features.mat' | |
h = h5py.File(file_path, 'r') | |
#dv - Distance Value | |
dv = h["worm"]["locomotion"]["motion"]["backward"]["frames"]["distance"].value | |
#NOTE, frames has an attribute: | |
#'MATLAB_class': 'struct' | |
# | |
#In Matlab, the object should really be an array of objects | |
#where the # of references of any given property are really | |
#indicative of the # of objects | |
# | |
#i.e. if distance has 28 values, then frames should be of length 28 | |
# | |
# The value held by the reference can be any length, however | |
# for many of our structure arrays (I think all) the values | |
# are scalar, so we can translate this all into an array of values or a list | |
# | |
#dv -> holds an array of references | |
#pass references to file to dereference | |
# | |
# h[dv[#,0]] | |
# | |
#Once we dereference to a dataset, we need to grab its value | |
# | |
# .value | |
# | |
#This value is an array, for which we grab the first value | |
#i.e. ASSUMES a scalar | |
# | |
# [0,0] | |
value = [h[dv[x,0]].value[0,0] for x in range(0,dv.size)] | |
plt.plot(value) | |
plt.show() | |
#NOTE: Should check len(value) == dv.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment