Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6639357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:32:41+00:00 2026-05-25T23:32:41+00:00

I am very new to matlab and python and need to use some values

  • 0

I am very new to matlab and python and need to use some values in python from the matlab cell array.

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]])]]

and the print out continues on.

Could someone explain to me how the cell array is arranged? (so how many dimensions is the above?)

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:32:42+00:00Added an answer on May 25, 2026 at 11:32 pm

    I imagine loadmat('file.mat') returns an instance of a shelve-class, that is inherited from the dict class. I assume you are using the loadmat function from scipy.io?

    from scipy.io import loadmat
    

    The scipy doc only mentions loadmat() returns a dictionary, but my guess is that the returned object a in your example is an open shelve-file, and you can no longer access its content when a is closed, which might happen for several reasons apart from calling a.close() mannually.

    To prevent this, copy all data into a real dictionary first, while loading this data:

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

    Now you can retrieve all keys and values from mat_dict:

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

    note that this is a valid solution as long as you are testing and figuring out what the mat_dict data is all about. In your script/model/function you would tipically load only the part of the shelve dict that you want, and then close the file explicitly:

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

    I don’t know if the with statement works (shelve does not support it as yet), you’ll have to test it, but it should handle closing even when an exception is thrown during loading of a:

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

    edit: subclass from numpy array to add additional attributes

    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() 
    

    so now if you want your array resembling the matlab structure, you do:

    >>> 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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Matlab and I'm looking for some advice from someone who
I very new to Python, and fairly new to regex. (I have no Perl
I am very new to matlab and image processing toolbox. I have a source
Very new to PHP5 and have some problems still. I figured out how to
Im very new to C programing, but have limited experience with Python, Java, and
Very new to AJAX, but have learned a bit from online tutorials. If I
I have a Binary classification problem that I need to do in MATLAB. There
Im very new to SQL but need to write a query to do the
I still very new using Subversion. Is it possible to have a working copy
I am very new to creating webservers - and I have had several goes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.