title: Exporting data to .mat file in python
body: <p>I am working on a script in python where I can pipe <code>ls</code> output to the script and open all the files I want to work with in python using <code>scipy.io</code>, and then I want to take all the imported data, and assign them into a <code>.mat</code> file (again using <code>scipy.io</code>). I have had success importing the data and assigning it to a dictionary to export, but when I load my output file in MATLAB none of the data looks at all the same.</p>
  
  <p>The data I am importing all has a lat/lon coordinate attached to it so I will use that data as an example. Data is coming from a netCDF (<code>.nc</code>) file:</p>
  
  <pre><code>    #!/usr/bin/python
      import sys
      import scipy.io as sio
      import numpy as np
  
      # script take absolute path inputs (or absolute paths are desirable)
      # to access an abolute path on a linux systen use the command:
      # ls -d $PWD/* OR if files not in PWD then ls -d /absolute_file_path/*
      # and then pipe the standard output of that to input of this script
  
      # initialize dictionary (param) and cycle number (i.e. datafile number)
      cycle = []
      param = {}
  
      # read each file from stdin
      for filename in sys.stdin:
          fh = sio.netcdf.netcdf_file(filename,'r')
          # load in standard variables (coordinates)
          latitude = fh.variables['LATITUDE'][:]
          longitude = fh.variables['LONGITUDE'][:]
  
          # close file
          fh.close()
  
          # get file number (cycle number)
          cycle = filename[-7:-4]
  
          # add latest imported coordinate to dictionary
          latvar = 'lat' + cycle
          lonvar = 'lon' + cycle
          param.update({latvar:latitude})
          param.update({lonvar:longitude})
  
      # export dictionary to .mat file
      sio.savemat('test.mat',param)
  </code></pre>
  
  <p>When I print the values to check if they are imported correctly I get reasonable values - but when I open my exported values in MATLAB this is an example of my output:</p>
  
  <pre><code>    &gt;&gt; lat001
  
      lat001 =
  
       -3.5746e-133
  </code></pre>
  
  <p>and other variables have similar large exponent value (sometime very small as in this example sometimes extremely large ~1e100).</p>
  
  <p>I have tried looking for similar problems but all I have come across is that some have had issues assigning large amounts of data to a single .mat file (ex. an array exceeding 2**32-1 bytes).</p>
  
  <p><strong>EDIT</strong>: Some example outputs (loading file in python, datatypes)</p>
  
  <pre><code>    print latitude
          [ 43.091]
  
      print type(latitude)
          &lt;type 'numpy.ndarray'&gt;
  
      data = sio.loadmat('test.mat')
      print data['lat001']
          array([[ -3.57459142e-133]])
  </code></pre>