How do I invoke a piece of Python code created and maintained in the Aptana IDE, within my MATLAB code.

I've consulted the documentation for calling Python functions from MATLAB (<http://www.mathworks.com/help/matlab/matlab_external/call-user-defined-custom-module.html>)
This file says "Change your current folder to a writable folder." I'm not clear where I'm supposed to be when I do this. I would expect that I should be in my Aptana IDE, where I develop my Python code, and that the Aptana folder -- already writable -- is the "current folder". But this is quite unclear, because the next line in the documentation says:
"Open a new file in MATLAB® Editor."
I would expect that to be from the MATLAB IDE, which is in a completely different part of my file system. The next line in the documentation says:
"Copy these commands and save the file as mymod.py."
But I can't do that in the MATLAB IDE, so this must mean in Aptana. A little later the documentation says:
"In the mymod.py source file, read the function signature for the search function. The function takes one input argument, words."
I'm afraid I don't know what it means to "read the function" here. Does it mean I should set up a Python main() within which I get this defined? I'd sure appreciate something spelled out in smaller steps. I can't get this important capability to work. Thx.

 Accepted Answer

All the commands and instructions in that example should be performed in MATLAB (well, almost all; see my second paragraph.) So change the current directory of MATLAB to some directory for which you have write permissions and create the mymod.py file in that directory. Technically you don't need to create the mymod.py file using the MATLAB Editor. You could use whatever editor you want, but since you're reading the documentation for MATLAB it's assuming you have MATLAB and the MATLAB Editor available.
"read the function signature" means literally for you (the human reading and/or working through the example) to read the signature of the function named search in the .py file that you created earlier in the example. I suspect that instruction is present in the example for the benefit of MATLAB programmers who may not be as familiar with Python syntax, to indicate and draw attention to where and how the Python functions used later in the example are defined. After all this example is in the "Getting Started with Python" section of the documentation, so it shouldn't assume very much (or any) knowledge of Python.

1 Comment

OK! All works. Just a matter of getting my "cd"'s right and paths pointing to the intended code. Thx!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!