{"action":"created","issue":{"url":"https://api.github.com/repos/arokem/python-matlab-bridge/issues/63","labels_url":"https://api.github.com/repos/arokem/python-matlab-bridge/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/arokem/python-matlab-bridge/issues/63/comments","events_url":"https://api.github.com/repos/arokem/python-matlab-bridge/issues/63/events","html_url":"https://github.com/arokem/python-matlab-bridge/pull/63","id":30970826,"number":63,"title":"Pythonic API","user":{"login":"hbristow","id":1771288,"avatar_url":"https://avatars.githubusercontent.com/u/1771288?v=3","gravatar_id":"","url":"https://api.github.com/users/hbristow","html_url":"https://github.com/hbristow","followers_url":"https://api.github.com/users/hbristow/followers","following_url":"https://api.github.com/users/hbristow/following{/other_user}","gists_url":"https://api.github.com/users/hbristow/gists{/gist_id}","starred_url":"https://api.github.com/users/hbristow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hbristow/subscriptions","organizations_url":"https://api.github.com/users/hbristow/orgs","repos_url":"https://api.github.com/users/hbristow/repos","events_url":"https://api.github.com/users/hbristow/events{/privacy}","received_events_url":"https://api.github.com/users/hbristow/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2014-04-07T09:49:34Z","updated_at":"2015-02-18T03:21:49Z","closed_at":"2015-02-18T03:21:49Z","pull_request":{"url":"https://api.github.com/repos/arokem/python-matlab-bridge/pulls/63","html_url":"https://github.com/arokem/python-matlab-bridge/pull/63","diff_url":"https://github.com/arokem/python-matlab-bridge/pull/63.diff","patch_url":"https://github.com/arokem/python-matlab-bridge/pull/63.patch"},"body":"This pull request introduces a new pythonic API to Matlab. The functionality is experimental at the moment. If you like this direction, let me know and I can solidify the implementation and remove deprecated code. **Don't merge this pull request in its current state**. I want to know what you think before I spend any sizable amount of time on it.\r\n\r\n### Features\r\n\r\n##### Matlab functions are Python functions\r\n\r\n```python\r\n# call matlab functions\r\nmatlab.sqrt(5) --> 2.23606797749979\r\nmatlab.min([5, 4]) --> 4\r\n\r\n# bind matlab functions to local variables\r\nsqrt = matlab.sqrt\r\n\r\n# matlab functions are real functions\r\ncallable(matlab.sqrt) --> True\r\ntype(matlab.sqrt) --> instancemethod\r\nprint(matlab.sqrt) --> <bound method Matlab.sqrt (verified)>\r\n```\r\n\r\nThis allows us to use a bunch of builtin Matlab functionality natively rather than rewrite it ourselves\r\n\r\n```python\r\n# get version info\r\nmatlab.version() --> '7.13.0.564 (R2011b)'\r\n\r\n# run a script\r\nmatlab.run('/path/to/script.m')\r\n\r\n# call a function not currently on the matlab path\r\nmatlab.addpath('/path/to/func')\r\nmatlab.func(args)\r\n\r\n# evaluate an arbitrary expression\r\nmatlab.eval('svd([5 4; 2 1])')\r\n```\r\n\r\n##### Keyword Arguments\r\n\r\nFunctions that take optional named arguments using Matlab's name, value hack (plotting, etc) can use Python's native keyword arguments syntax\r\n\r\n```python\r\nmatlab.plot(x, y, '--', LineWidth=2, MarkerSize=10)\r\n```\r\n\r\n##### Number of Output Arguments\r\n\r\nThe behaviour of many Matlab functions changes depending on how many output arguments are provided (seriously, who thought of that...). An option `nout` argument can be supplied to indicate how many outputs are desired\r\n\r\n```python\r\nmatlab.min([5, 4]) --> 4\r\nmatlab.min([5, 4], nout=2) --> (4, 2)\r\n```\r\n\r\n##### Native Python docstrings\r\n\r\nHelp is provided via Python's builtin `help()` function.\r\n\r\n```python\r\nhelp(matlab.sqrt)\r\n```\r\n\r\ndocstrings are cached, so they are only fetched from Matlab once.\r\n\r\n##### Exceptions\r\n\r\nMatlab exceptions are captured and re-raised as Python exceptions to indicate errors\r\n\r\n```python\r\n# non-existent function\r\nmatlab.asdkfjhasdlfjn() --> raises AttributeError: 'Matlab' object has no attribute 'asdkfjhasdlfjn'\r\n\r\n# bad inputs\r\nmatlab.min() --> raises RuntimeError: MATLAB:minrhs: Not enough input arguments.\r\n```\r\n\r\nIf a non-existent function name is called, that function name is blacklisted so subsequent attempts to call that function immediately throw an exception.\r\n\r\n#### Give it a try!\r\n\r\nAnd let me know what you think"},"comment":{"url":"https://api.github.com/repos/arokem/python-matlab-bridge/issues/comments/74804723","html_url":"https://github.com/arokem/python-matlab-bridge/pull/63#issuecomment-74804723","issue_url":"https://api.github.com/repos/arokem/python-matlab-bridge/issues/63","id":74804723,"user":{"login":"blink1073","id":2096628,"avatar_url":"https://avatars.githubusercontent.com/u/2096628?v=3","gravatar_id":"","url":"https://api.github.com/users/blink1073","html_url":"https://github.com/blink1073","followers_url":"https://api.github.com/users/blink1073/followers","following_url":"https://api.github.com/users/blink1073/following{/other_user}","gists_url":"https://api.github.com/users/blink1073/gists{/gist_id}","starred_url":"https://api.github.com/users/blink1073/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blink1073/subscriptions","organizations_url":"https://api.github.com/users/blink1073/orgs","repos_url":"https://api.github.com/users/blink1073/repos","events_url":"https://api.github.com/users/blink1073/events{/privacy}","received_events_url":"https://api.github.com/users/blink1073/received_events","type":"User","site_admin":false},"created_at":"2015-02-18T03:21:48Z","updated_at":"2015-02-18T03:21:48Z","body":"Implemented in #145."}}