首页 > 解决方案 > 如何使用字符串作为输入从 Matlab 调用 Matlab 函数

问题描述

我想my_function(string1,string2)从 Python 运行一个自写的 Matlab 函数,我尝试使用这个命令: !matlab -nosplash -r my_function(string1,string2)

当我给两个特定的字符串作为输入变量时,这有效 !matlab -nosplash -r my_function('myfirststring','mysecondstring'),但是当我给两个字符串变量时它不起作用:

string1='myfirststring'
string2='mysecondstring'
!matlab -nosplash -r my_function(string1,string2)

Matlab 给出错误信息:

Undefined function or variable 'string1'. 

如何将实际字符串提供给 Matlab 函数而不是变量名?

标签: pythonmatlab

解决方案


推荐阅读