Matlab arrays to / from Python
Passing N-dimensional arrays to / from Python from Matlab is straightforward with Matlab. Matlab can work with Python classes including list(), dict(), set(), Numpy.ndarray and Xarray.DataArray.
Matlab using Numpy example:
Matlab using Xarray: see example glow.m.
function M = xarray2mat(V)
M = double(py.numpy.asfortranarray(V));
end
function I = xarrayind2vector(V,key)
% convert xarray index to Matlab 1-D vector
I = cell2mat(cell(V.indexes{key}.values.tolist));
end
Related:
- Call Matlab from Python
- Matlab calling Python with xarray and other advanced data modules