对于 MATLAB 中的"The command is too long to execute"错误,可以做些什么?



我正在从MATLAB中调用一个Python程序,并将一个数组传递给该程序。我正在MATLAB工作空间中写以下几行:

% Let us assume some random array
num1 = ones(1,100);   
% I am forced to pass parameters as string due to the MATLAB-Python interaction.
num2 = num2str(num1);    
% The function is saved in a Python program called squared.py
z=python('squared.py',num2);

num1的大小较小(例如100)时,程序工作良好。然而,当它很大时,例如500000,MATLAB显示以下错误:

??? Error using ==> dos
The command is too long to execute.
Error in ==> python at 68
[status, result] = dos(pythonCmd);

有人知道如何修复这个错误吗?

在Windows上,传递给dos函数的命令限制为32768个字符。此限制来自Windows对CreateProcess的lpCommandLine参数的限制。

我认为Fredrik将数据写入文件并从Python中读取的想法是最好的选择。

相关内容