Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
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
);
y = py_np2m(data
);
%% 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')
Gliffy Diagrams
Attachments
1.
|
Package MATLAB toolbox with distribution |
|
Closed | Unassigned |
|
|||||||
2.
|
Include MATLAB demo html on doc site |
|
Closed | Marmaduke Woodman |
|