필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2024년 4월 23일
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
Amin
Amin 2024년 4월 24일
편집: Amin 2024년 4월 24일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by