-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertMatriciesToNumPy.m
41 lines (34 loc) · 1.14 KB
/
ConvertMatriciesToNumPy.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [varargout] = ConvertMatriciesToNumPy(varargin)
%ConvertMatriciesToNumPy Assuming the input matricies are the same shape.
% Pass in MATLAB matricies and this will convert these to Numpy format
% with the right shape and size. Requires a linked working version of
% Python in your MATLAB build.
%Assign correct size (Make sure you have the same number of input args as
%outputs).
varargout=varargin;
%Convert to Python (Need to be vectors to convert)
Size=size(varargin{1}); %Get size for reshaping in python
InputsSize=numel(varargin);
try
Size = py.numpy.array(Size);
catch
disp('Python not loaded correctly with MATLAB')
for i=1:InputsSize
inputname(i)
writeNPY(varargin{i}, strcat(inputname(i),'.npy'))
end
return %leave func here
end
for i=1:InputsSize
%Assign 2 temp array
temp=varargin{i};
%Transpose
temp=temp';
%Make a vector (MATLAB requires these are vectors before conversion.
temp = py.numpy.array(temp(:).');
%Call Python function that reshapes the matricies
temp=py.Mat2Py.Mat2PyFunc(temp,Size);
%Assign arg to outputs
varargout{i}=temp;
end
end