1

I'm translating some MATLAB code into Python and I need to access data structures. Using scipy, I need to concatenate a user input string into a filename:

cb_data = scipy.io.loadmat('./cb_data/' + subj_id + '_cb_AAAD_V2.mat' , 'rb')

where subj_id is a variable coming from user input. I have also tried inputting the user input directly but it returned the same error

File "/Users/pproctor/anaconda/PythonScripts_conda/get_num_trials.py",line 36, in 
get_num_trials cb_data = scipy.io.loadmat('./cb_data/' + subj_id + '_cb_AAAD_V2.mat'  , 'rb')

File "/Users/pproctor/anaconda/lib/python2.7/site-packages/scipy
/io/matlab/mio.py", line 137, in loadmat mdict.update(matfile_dict)

AttributeError: 'str' object has no attribute 'update'

1 Answer 1

2

The second argument, mdict, of loadmat is not the file access mode. It is optional, but if it is given, it must be a dictionary. The loaded arrays are added to this dictionay, with the variable names as keys and the actual arrays as values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.