-1

I am having problems calling a Python function in Matlab. I have already researched my question with little joy, the question has already been answered on this website, Call Python function from MATLAB, but I can't seem to get the solution to work for me.

I understand that a lot of people will suggest I just scrap using Matlab and use Python but my boss requires me to code in Matlab. I am using a simple squared function just to figure out how to call the python function in to Matlab, as suggested in the previous solution, Call Python function from MATLAB.

Thanks for your time.

Community
  • 1
  • 1
user2519890
  • 157
  • 2
  • 14
  • 2
    If your boss "requires" you to code in Matlab, what makes you think he'll be happy about this Python junket? More to the point, can you explain a little bit about how the logic/code will be divided between the two languages, and what sort of data will flow between? – John Zwinck Jun 25 '13 at 12:00
  • 1
    What operating system are you working on? – ChrisProsser Jun 25 '13 at 12:06
  • I tend to agree with @JohnZwinck on this one - if you are required to use Matlab, why not translate your Python function into Matlab? – Schorsch Jun 25 '13 at 12:17
  • 2
    Why can't you get the solutions from the other question to work for you? Which one of the solutions given in the answers to that question did you attempt? What have you tried? (PS I wouldn't suggest you scrap MATLAB and use Python - I'd suggest that you do what your boss has told you to do and use MATLAB). – Sam Roberts Jun 25 '13 at 12:18
  • I am after the beta distribution function and it doesn't make sense to me to buy the statistics toolbox for one function, so it will just be an argument going to python returning an answer to be used in Matlab. I have discussed with my boss and he is happy for me to use python for this function but wants the majority of the code written in Matlab. I am using windows 7, Matlab 2012 and python 3.3. – user2519890 Jun 25 '13 at 13:00
  • SamRoberts, I was trying to use the first solution which had the highest rating. – user2519890 Jun 25 '13 at 13:11

1 Answers1

0

In case it helps here is a some info on how to execute an operating system command from MatLab: http://www.mathworks.co.uk/help/matlab/ref/system.html

If you cannot find a more direct method of calling python, you could use the above to call a python script from your OS e.g. the command inside the above would be

python path_to_script.py [arg_1] [arg_n]

A few pointers here, to call Python like this it needs to be a recognised environment variable, if not either add it or use the full path. Any arguments (including the script name) need to be enclosed with double quotes if they contain any spaces.

ChrisProsser
  • 12,598
  • 6
  • 35
  • 44