running matlab exe file results in “Too many input arguments. MATLAB:TooManyInputs error”
When compiling a MATLAB (.m) function (main_file below is code) into a standalone executable (.exe) through MATLAB Compiler, the command-line arguments passed to the executable are not being accepted. Instead of parsing the arguments through the getmcruserdata(‘syscommandargs’) function within the compiled MATLAB application, MATLAB is throwing an error, stating there are "Too many input arguments. the following code works fine when i dont pass any args (main_file.exe). however with passign args I get error. Note that I expect when i pass args the disp(‘Not enough arguments received.’); print message but it does not. I made the following function to exe which is named main_file.exe. Running main_file.exe "test1args" "test2args" results in error (Too many input arguments. MATLAB:TooManyInputs). Please help me to resolve it. Thanks.
function main_file
param1 = ‘test1args’;
param2 = ‘test2args’;
if isdeployed
disp("Reading input arguments");
args = getmcruserdata(‘syscommandargs’);
if isempty(args)
disp(‘Not enough arguments received.’);
else
% Parse args
args_cell = strsplit(args{1}, ‘ ‘);
if numel(args_cell) >= 2
param1 = args_cell{1};
disp(param1);
param2 = args_cell{2};
disp(param2);
else
disp(‘more than 2 arguments received.’);
end
end
else
disp(‘Running in MATLAB’);
param1 = ‘test1args’;
disp(‘test2args’);
disp(param1);
param2 = ‘Yes’;
disp(‘param2’);
disp(param2);
end
disp("hello from executable…")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, ‘process’, param2);
disp("process done")
endWhen compiling a MATLAB (.m) function (main_file below is code) into a standalone executable (.exe) through MATLAB Compiler, the command-line arguments passed to the executable are not being accepted. Instead of parsing the arguments through the getmcruserdata(‘syscommandargs’) function within the compiled MATLAB application, MATLAB is throwing an error, stating there are "Too many input arguments. the following code works fine when i dont pass any args (main_file.exe). however with passign args I get error. Note that I expect when i pass args the disp(‘Not enough arguments received.’); print message but it does not. I made the following function to exe which is named main_file.exe. Running main_file.exe "test1args" "test2args" results in error (Too many input arguments. MATLAB:TooManyInputs). Please help me to resolve it. Thanks.
function main_file
param1 = ‘test1args’;
param2 = ‘test2args’;
if isdeployed
disp("Reading input arguments");
args = getmcruserdata(‘syscommandargs’);
if isempty(args)
disp(‘Not enough arguments received.’);
else
% Parse args
args_cell = strsplit(args{1}, ‘ ‘);
if numel(args_cell) >= 2
param1 = args_cell{1};
disp(param1);
param2 = args_cell{2};
disp(param2);
else
disp(‘more than 2 arguments received.’);
end
end
else
disp(‘Running in MATLAB’);
param1 = ‘test1args’;
disp(‘test2args’);
disp(param1);
param2 = ‘Yes’;
disp(‘param2’);
disp(param2);
end
disp("hello from executable…")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, ‘process’, param2);
disp("process done")
end When compiling a MATLAB (.m) function (main_file below is code) into a standalone executable (.exe) through MATLAB Compiler, the command-line arguments passed to the executable are not being accepted. Instead of parsing the arguments through the getmcruserdata(‘syscommandargs’) function within the compiled MATLAB application, MATLAB is throwing an error, stating there are "Too many input arguments. the following code works fine when i dont pass any args (main_file.exe). however with passign args I get error. Note that I expect when i pass args the disp(‘Not enough arguments received.’); print message but it does not. I made the following function to exe which is named main_file.exe. Running main_file.exe "test1args" "test2args" results in error (Too many input arguments. MATLAB:TooManyInputs). Please help me to resolve it. Thanks.
function main_file
param1 = ‘test1args’;
param2 = ‘test2args’;
if isdeployed
disp("Reading input arguments");
args = getmcruserdata(‘syscommandargs’);
if isempty(args)
disp(‘Not enough arguments received.’);
else
% Parse args
args_cell = strsplit(args{1}, ‘ ‘);
if numel(args_cell) >= 2
param1 = args_cell{1};
disp(param1);
param2 = args_cell{2};
disp(param2);
else
disp(‘more than 2 arguments received.’);
end
end
else
disp(‘Running in MATLAB’);
param1 = ‘test1args’;
disp(‘test2args’);
disp(param1);
param2 = ‘Yes’;
disp(‘param2’);
disp(param2);
end
disp("hello from executable…")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, ‘process’, param2);
disp("process done")
end standalone-application, matlab-compiler, command-line-arguments, executable MATLAB Answers — New Questions