Filter löschen
Filter löschen

running matlab exe file results in "Too many input arguments. MATLAB:TooManyInputs error"

5 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Apr. 2024
You need
function main_file(varargin)
When you compile an executable, command line arguments are passed as parameters to the main function . You defined function main_file without parameters, so running with no parameters at least gets the code started, but running with parmeters immediately fails for having passed extra parameters to main_file
  1 Kommentar
Amin
Amin am 24 Apr. 2024
Bearbeitet: Amin am 24 Apr. 2024
thanks. the following resolve the issue.
function main_file(varargin)
p = inputParser;
addParameter(p,'case1','case1_val',@ischar);
addParameter(p,'case2','case2_val',@ischar);
parse(p, varargin{:});
param1 = p.Results.case1;
param2 = p.Results.case2;
if isdeployed
disp('Running using exe');
disp("Reading input arguments");
disp(p.Results)
else
disp('Running in MATLAB');
disp(['case1: ', param1]);
disp(['case2: ', param2]);
end
disp("hello from executable...")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, 'process', param2);
disp("process done")
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by