passing variable from matlab to python using pyrunfile
    조회 수: 10 (최근 30일)
  
       이전 댓글 표시
    
Hi all,
I've been looking to find an answer for the following question;
I have a variable in my workspace that I need to use in a python script, which for some reason is more challenging in than expected. I have been looking around the Mathlab documentation which unfortunately has not been helpfull for me.
Any help to solve this would  be greatly appreciated!
Sample code which I simplified for this message.
% Matlab: This is the line that calls function.py using var01, var02 and var03.
apply_cnn_command = pyrunfile ("function.py '" + var01 + var02 + var03+"'")
% In Python I am using the current code: 
import sys
import os
import matlab.engine
eng= matlab.engine.start_matlab()
varpy01 = eng.workspace[var01]
% The error message: "Python Error: NameError: name var01 is not defined.
댓글 수: 0
답변 (1개)
  Pavan Sahith
      
 2024년 5월 12일
        
      편집: Pavan Sahith
      
 2024년 5월 12일
  
      Hello Janssen,
It seems you are looking for a way to pass variables from MATLAB to python.
You can refer to the following MATLAB Answers which will give you some guidance 
Hope this information will help you in getting started.
댓글 수: 3
  Walter Roberson
      
      
 2024년 5월 12일
				
      편집: Walter Roberson
      
      
 2024년 5월 12일
  
			apply_cnn_command = pyrunfile ("function.py '" + var01 + var02 + var03+"'")
Do you have some kind of seperators built into var01 var02 var03 so that the parser can break apart the pieces?
I would have expected something closer to
apply_cnn_command = pyrunfile ("function.py '" + var01 + " " + var02 + " " + var03+"'")
참고 항목
카테고리
				Help Center 및 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!


