我从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);
Run Code Online (Sandbox Code Playgroud)
当尺寸num1很小(例如100)时,程序工作正常.但是,当它很大,例如500000时,MATLAB显示以下错误:
??? Error using ==> dos
The command is too long to execute.
Error in ==> python at 68
[status, result] = dos(pythonCmd);
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个错误?
在Windows上,传递给该dos函数的命令限制为32768个字符.此限制来自Windows lpCommandLine对CreateProcess参数的限制.
我认为Fredrik将数据写入文件并从Python读取数据的想法是您的最佳选择.