From b03b0d81f4b882bc49be561f67973c130e452dd2 Mon Sep 17 00:00:00 2001 From: Yoav Ram Date: Wed, 21 Dec 2016 15:11:50 +0200 Subject: [PATCH] format code snippets --- README.md | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2e0db96..0659a2a 100644 --- a/README.md +++ b/README.md @@ -10,41 +10,55 @@ This has not been tested on Windows. Initialize the Matlab class. You must pass in your matlab executable, e.g. - from pymatbridge import Matlab - mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab') +```py +from pymatbridge import Matlab +mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab') +``` By default the host is localhost and the port is 4000. This can be changed, e.g. - mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab', - host='192.168.0.1', port=5151) +```py +mlab = Matlab( + matlab='/Applications/MATLAB_R2011a.app/bin/matlab', + host='192.168.0.1', + port=5151 +) +``` You must then start the MATLAB server: - mlab.start() +```py +mlab.start() +``` which will return True once connected. You can then run any local MATLAB function contained within a .m file of the same name. For example, to call the function jk in jk.m: - %% MATLAB - function lol = jk(args) - arg1 = args.arg1; - arg2 = args.arg2; - lol = arg1 + arg2; - end - +```matlab +%% MATLAB +function lol = jk(args) + arg1 = args.arg1; + arg2 = args.arg2; + lol = arg1 + arg2; +end +``` by calling: - res = mlab.run('path/to/jk.m', {'arg1': 3, 'arg2': 5}) - print res['result'] +```py +res = mlab.run('path/to/jk.m', {'arg1': 3, 'arg2': 5}) +print res['result'] +``` which will print 8. You can shut down the MATLAB server by calling - mlab.stop() +```py +mlab.stop() +``` -NB: you can call MATLAB code before the server starts by adding code to the ./matlab/startup.m file. +NB: you can call MATLAB code before the server starts by adding code to the `./matlab/startup.m` file. # Example