Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can be done about "The command is too long to execute" error in MATLAB?

Tags:

python

matlab

I am calling a Python program from MATLAB and passing an array to the program. I am writing the following lines in MATLAB workspace:

% 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?

like image 419
Nazmul Avatar asked Feb 24 '23 22:02

Nazmul


1 Answers

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.

like image 85
SCFrench Avatar answered Feb 26 '23 21:02

SCFrench