我想发布一个Matlab代码,它需要用户的一些输入(单个字符串)代码运行良好,但当我试图发布它时

Error using input
Cannot call INPUT from EVALC.
Error in test (line 185)
userinput = input('Enter the code here\n', 's');

有什么解决办法吗?

最佳答案

如果单击“发布”按钮旁边的小下拉菜单,将看到一个名为“编辑发布配置”的项如果选择该选项(当要发布的文件在编辑器中打开时),将看到可以编辑的MATLAB表达式这是在发布脚本时执行的MATLAB代码,默认情况下它只是脚本的名称。
假设您的脚本名为myscript,因此默认情况下,发布的表达式是

myscript

可以将表达式编辑为:
userinput = 'example';
myscript

然后,当您单击发布按钮时,将运行此操作。
在脚本中,更改行
userinput = input('Enter the code here\n', 's');


if ~exist('userinput', 'var')
    userinput = input('Enter the code here\n', 's');
end

现在脚本将正常运行(假设工作区中没有变量“userinput”),并且脚本将成功发布。
希望能有帮助!

09-11 18:48
查看更多