execute cell content as lines of command in Matlab

18 ビュー (過去 30 日間)
Hamid
Hamid 2022 年 1 月 26 日
コメント済み: Hamid 2022 年 2 月 3 日
I have a cell that cintains execution command such as
A{1} = python run_my_code -m var1="1" var2 ="2"
A{2} = python run_my_code -m var1="2" var2 ="4"
...
When I use system(A{1}) it gives me sytax error.
The idea is to run all cell contetnts in a for loop within matlab.
Any help is appreciated
  3 件のコメント
Hamid
Hamid 2022 年 1 月 28 日
I should have mentioned that var=1,2 are the predefined arugments of my Python code. I can run the exat line of code (e.g., python run_my_code -m var1="2" var2 ="4") in the terminal but when I use system(python run_my_code -m var1="2" var2 ="4") it give me the syntax error. The madules that my Python code uses is in an specific conda environment and perhaps system command does not recognize this.
DGM
DGM 2022 年 1 月 28 日
I am not familiar with python, but if the errors are with python instead of matlab, then environment configuration sounds like something worth looking into.

サインインしてコメントする。

回答 (1 件)

Yongjian Feng
Yongjian Feng 2022 年 1 月 29 日
Try this first from matlab command line window:
pe = pyenv
This will tell you what python env is used by your matlab installation.
  1 件のコメント
Hamid
Hamid 2022 年 2 月 3 日
Thanks for the suggestion Yongjian Feng. I found setting the conda environment difficult for different operating systems as I am working withing different platforms. The easiest way for me was to set the environment in Terminal.
  1. 'conda activate envx'
  2. bring up Matlab from terminal (instead of shortcut)
  3. run the matlab script within which the system(A{1}) is set to call and run Python.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by