What can be done about "The command is too long to execute" error in MATLAB?
I am calling a Python program from MATLAB and passing an array to the program. I am writing the following lines in MATLAB wo开发者_运维技巧rkspace:
% 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);
The program works fine when the size of num1
is small (e.g. 100). However, when it is large, e.g., 500000, MATLAB shows the following error:
??? Error using ==> dos
The command is too long to execute.
Error in ==> python at 68
[status, result] = dos(pythonCmd);
Does anyone know how to fix this error?
On Windows, the command passed to the dos
function is limited to 32768 characters. This limitation comes from the Windows limitation on the lpCommandLine
parameter to CreateProcess.
I think Fredrik's idea of writing the data to a file and reading it from Python is your best alternative.
精彩评论