ndarkness
ndarkness

Reputation: 1089

How can I save my array into a matlab struct in Python?

I have loaded some struct (called sensor) into python from my Matlab by doing this

from scipy.io import loadmat
pathToData="C:\Projects\"
fileName = "\sensor.mat"
pathToData = pathToData + fileName
matfile = loadmat(pathToData, squeeze_me=True, struct_as_record=False)
sensor = matfile['sensor']

I can read the data properly but now I would like to write into it some results from python. THe struct has already the field gDist, but I cannot write onto them, why is that?

vmag_in = sensor.vmag_mv[0:sampleN]
vphs_in = sensor.vphs_mv[0:sampleN]
k = 0
for v_mag,v_phs in zip(vmag_in,vphs_in):
    gDist= functionA(v_mag, v_phs,sensor.content[k])

    sensor.gDist[k] = gDist # <-This seems not working?

    # Iterate counter
    k = k +1     

Upvotes: 0

Views: 226

Answers (1)

user3600100
user3600100

Reputation: 43

matlab struct array start from 1 ther for the Iterate counter k = k +1 most be in the first for loop line

Upvotes: 0

Related Questions