f



Python

You can run Python from the Windows Command Prompt and Matlab can
send commands to the Windows Command Prompt.

So far so good...

But when I try and run Python from Matlab behaving as the Windows
command prompt, nothing happens - where am I going wrong?

Many thanks

Leo
0
6/20/2007 10:22:38 AM
comp.soft-sys.matlab 211264 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
545 Views

Similar Articles

[PageSpeed] 52

Leo,

if you have trouble implementing something that you got as an answer
to your posting, it's definitely better to continue the thread
instead of staring a new one. That way, other people can see what's
been done to solve the problem. Also, the guy who spend some time to
help you does not feel ignored.

The reply I gave you to your posting "Matlab and Python" a few days
ago should work if you fill in the proper path information; if it
does not work for you, you should describe what you get on the basis
of the previous answer. It is very rare that *nothing* happens! As
you see below, the system command is supposed to return a value. That
value should 'happen', even if the command you issue has no effect.

If you have, for instance, the file 'hello.py' in your Python home
directory 'C:\Python25\', with the content:

print "Hello world!"

and you type

system('C:\Python25\hello.py')

into your Matlab command window, you should see:

>> system('C:\Python25\hello.py')
Hello world!
ans =
     0

This assumes Windows, and the extension '.py' must be registered,
such that the OS knows it must start the python interpreter to run a
python script. If not, this should work:

system('C:\Python25\python C:\Python25\hello.py')

Regards,

Heinrich
0
6/20/2007 1:00:28 PM
I am actually asking a question to Heinrich about calling a python function from Matlab. Sorry Leo, I might be spamming your inbox.

Heinrich,

I need to call a python function from a Matlab environment. Is it possible?

Let's assume, I have the following python code:

def squared(x):
    y = x * x
    return y

I want to call squared(3) from Matlab workspace/code and get 9. 

I posted this msg in Matlab newsreader but no-one replied. That's why I am replying in this thread.

Nazmul

"Heinrich Acker" wrote in message <ef5b354.0@webcrossing.raydaftYaTP>...
> Leo,
> 
> if you have trouble implementing something that you got as an answer
> to your posting, it's definitely better to continue the thread
> instead of staring a new one. That way, other people can see what's
> been done to solve the problem. Also, the guy who spend some time to
> help you does not feel ignored.
> 
> The reply I gave you to your posting "Matlab and Python" a few days
> ago should work if you fill in the proper path information; if it
> does not work for you, you should describe what you get on the basis
> of the previous answer. It is very rare that *nothing* happens! As
> you see below, the system command is supposed to return a value. That
> value should 'happen', even if the command you issue has no effect.
> 
> If you have, for instance, the file 'hello.py' in your Python home
> directory 'C:\Python25\', with the content:
> 
> print "Hello world!"
> 
> and you type
> 
> system('C:\Python25\hello.py')
> 
> into your Matlab command window, you should see:
> 
> >> system('C:\Python25\hello.py')
> Hello world!
> ans =
>      0
> 
> This assumes Windows, and the extension '.py' must be registered,
> such that the OS knows it must start the python interpreter to run a
> python script. If not, this should work:
> 
> system('C:\Python25\python C:\Python25\hello.py')
> 
> Regards,
> 
> Heinrich
0
6/8/2011 3:35:11 PM
Reply: