running python script in matlab
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
1 개 추천
Hi, I have one python script and i want to execute that in matlab.I tried with system in matlab. s=system('python trail.py 3') while excuting this command i'm getting a error like below. 'python' is not recognized as an internal or external command, operable program or batch file. Please can anybody help me in fixing this error. Thanks in advance
Regards Vasavi
채택된 답변
Walter Roberson
2012년 6월 22일
Either python is not installed in your system or it is not on your MS Windows PATH as known to MATLAB.
Inside MATLAB, command
getenv('PATH')
and see what it shows.
Note: python is not automatically installed as part of MATLAB. perl is, though, installed as part of MATLAB.
댓글 수: 7
sai vasavi
2012년 6월 28일
Hello walter, Thanks for your response.I added python path to MS windows PATH.By adding this path that error got clear.Now,when I run the command like s=system("mypython.py"); this command just opening the corresponding python file but it is not executing in matlab. Actually,the requirement is I have created one function in python.I want to pass arguments to that function from matlab and saving the function output in matlab workspace. for illustration i have a function in python like in python environment define squared(x): y=x*x return y In Matlab environment, Squared(3) 9 Please help me in solving this. Regards Vasavi
Walter Roberson
2012년 6월 28일
One way of proceeding (I think) would be to use MS Windows facilities to "associate" the .py file extension with the python interpreter.
Another way would be to specify the python interpreter as the command, and use whatever flags python uses in order to indicate that what follows is the name of the script to execute. For example it might look like
s = system('python -f mypython.py');
I am not familiar with python's argument-passing mechanisms; I know some other people around have used python so one of them might know.
sai vasavi
2012년 7월 2일
Thanks for your comment Walter. I am also new to this python.Please share any information regarding this request if any.I searched in google but i did n't get any solution to solve this.
Thus for example
arg1 = 'C:\TEMP\MyInputFile.txt';
s = system( sprintf('python mypython.py "%s"', arg1) );
sai vasavi
2012년 7월 10일
Thanks for your response Walter.That issue is resolved.Now I am able to run that python function in matlab and saving the putput in workspace. I developed the code which can do the sam ehow perl functions are executed in matlab environment. Anyhow thanks for your help.
Sameer Khan
2013년 7월 15일
편집: Sameer Khan
2013년 7월 15일
sai vasavi: can you pleasse tell me how to run a mcros file with a .py extension in matlab? i want to get a .rpt file from abaqus simulation automatically for that i prepared a macros file with .py extension. I am new to abaqus and need help. or any other way to get the output values of displacements at a node for all time.?
Found that you can get results back from python invoked from matlab by using [s,r] return values for system call where the strings python emits can be captured and parsed. Might be good to use files holding larger amounts of data with names printed for matlab to pick up and read.
A simple test I did was to write a squaring function and pass args:
>> arg1 = "1 2 3 4 5";
>> [s,r] = system(sprintf('python pysqr.py %s', arg1));
>> r
r =
'argument 1: 1
arg: 1 - sqr: 1
argument 2: 2
arg: 2 - sqr: 4
argument 3: 3
arg: 3 - sqr: 9
argument 4: 4
arg: 4 - sqr: 16
argument 5: 5
arg: 5 - sqr: 25
'
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
