Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5
    • Component/s: None
    • Labels:
      None

      Description

      MATLAB 2014b quietly added a simple bridge to Python 2.7 / 3.

      {3,4}

      , which appears to use the C-API to Python directly. It is sufficient to transcribe our demos for the simulator, and obtain correct results, here is an example I worked out, I attached the generated figure, and a screenshot showing that MATLAB provides as much help on python objects as it does for its own datatypes.

      In MATLAB, fields are accessed with dot notation but methods are called like generic functions as in Julia.
      %% setup
      append(py.sys.path, '/Users/MW/Documents/TVB/TVB/scientific_library')
      append(py.sys.path, '/Users/MW/Documents/TVB/TVB/tvb_data')

      %% build simulator
      model = py.tvb.simulator.models.Generic2dOscillator(pyargs('a', 0.4));
      coupling = py.tvb.simulator.coupling.Linear;
      conn = py.tvb.datatypes.connectivity.Connectivity(...
      pyargs('load_default', py.True));

      sim = py.tvb.simulator.simulator.Simulator(pyargs(...
      'integrator', py.tvb.simulator.integrators.EulerDeterministic(...
      pyargs('dt', 1)),...
      'model', model, ...
      'coupling', coupling, ...
      'connectivity', conn));

      configure(sim);

      %% run simulation
      data = run(sim, pyargs('simulation_length', 1000));

      % small helper function handles conversion from NumPy to MATLAB arrays
      t = py_np2m(data

      {1}

      );
      y = py_np2m(data

      {1} {2}

      );

      %% Plot results
      %
      % Note that the dimensions are reversed because MATLAB uses a Fortran,
      % row-major layout, while NumPy uses C, column-major layout.

      figure(1)
      plot(t, squeeze(y(1, :, 1, ), 'k')

        Attachments

        1. example.png
          example.png
          12 kB
        2. helpers.py
          0.5 kB
        3. np2m.m
          1 kB
        4. Screen Shot 2015-07-03 at 14.55.09.png
          Screen Shot 2015-07-03 at 14.55.09.png
          566 kB
        5. test_py_tvb.m
          0.2 kB
        6. tvb_demo.m
          1 kB
        7. tvb-dist-matlab-crash.txt
          18 kB
        8. tvb-matlab-live-script.PNG
          tvb-matlab-live-script.PNG
          184 kB

          Activity

            People

            • Assignee:
              marmaduke.woodman Marmaduke Woodman
              Reporter:
              marmaduke.woodman Marmaduke Woodman
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1 day, 5 hours
                1d 5h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours Time Not Required
                7h