Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pymatbridge/matlab/util/pymat_feval.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
else
arguments = '';
end

[resp{1:nargout}] = run_dot_m(func_path, arguments);
response.result = resp;

[resp{1:req.nargout}] = run_dot_m(func_path, arguments, req.nargout);
if req.nargout == 1
response.result = resp{1};
else
response.result = resp;
end
response.success = 'true';
response.message = 'Successfully completed request';

Expand Down
27 changes: 12 additions & 15 deletions pymatbridge/matlab/util/run_dot_m.m
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
% Max Jaderberg 2011

function result = run_dot_m( file_to_run, arguments )
function varargout = run_dot_m( file_to_run, arguments, nout )
%RUN_DOT_M Runs the given .m file with the argument struct given
% For exmaple run_dot_m('/path/to/function.m', args);
% args is a struct containing the arguments. function.m must take only
% one parameter, the argument structure

[dir, func_name, ext] = fileparts(file_to_run);
[dname, func_name, ext] = fileparts(file_to_run);

if ~size(ext)
result = 'Error: Need to give path to .m file';
return
if size(ext)
if ~strcmp(ext, '.m')
varargout = 'Error: Need to give path to .m file';
return
end
end

if ~strcmp(ext, '.m')
result = 'Error: Need to give path to .m file';
return
% Add function path to current path
if size(dname)
addpath(dname);
end

% Add function path to current path
addpath(dir);
if isstruct(arguments)
result = feval(func_name, arguments);
else
result = feval(func_name);
end
[varargout{1:nout}] = feval(func_name, arguments);

end
5 changes: 3 additions & 2 deletions pymatbridge/pymatbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ def _json_response(self, **kwargs):
return json.loads(self._response(**kwargs), object_hook=decode_pymat)

# Run a function in Matlab and return the result
def run_func(self, func_path, func_args=None):
def run_func(self, func_path, func_args=None, nargout=1):
return self._json_response(cmd='run_function',
func_path=func_path,
func_args=func_args)
func_args=func_args,
nargout=nargout)

# Run some code in Matlab command line provide by a string
def run_code(self, code):
Expand Down