How to pass inputs to compiled matlab function with internal input statements?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have:
path1=input('Project Directory: ', 's');
dirname=input('Case Directory: ', 's');
filename=input('OPER Filename: ', 's');
in a compiled executable from Matlab. I can store the 3 inputs in a file and use them like this:
compiled_function < file_of_inputs
from the linux command line. I want to remove the file from the process and just command it as:
compiled_function 'input1' 'input2' 'input3'
or some other form of that. The reason being I want to skip the intermediate step of creating hundreds of input files that must be cleaned up later. When the code was written it was only being used on tens of files, now the process of creating all the input files is hurting throughput. I can rewrite and recompile if there is a better command to use.
댓글 수: 0
채택된 답변
Image Analyst
2015년 6월 1일
Did you try printing out the varargin{} cell array entries when you ran it? The command line arguments should be in that variable. Here's a snippet from one of my programs:
if isdeployed && ~isempty(varargin)
% For some reason, it won't take the command line as a single item, even if it's in double quotes.
% It splits it up and gets rid of leading and trailing spaces so that
% "D:\My Tests\ThisTest\Images"
% becomes 2 cells:
% varargin{1} = "D:\My
% varargin{2} = Tests\ThisTest\Images"
% We need to join all these together.
numberOfCells = length(varargin);
if numberOfCells >= 1
commandLineArgument = varargin{1};
for k = 2 : numberOfCells
thisWord = varargin{k};
% fprintf(1, 'varargin{%d} = %s\n', k, thisWord);
commandLineArgument = sprintf('%s %s', commandLineArgument, thisWord);
end
% Get rid of any quotes.
commandLineArgument = strrep(commandLineArgument, '"', []);
fprintf(1, 'The argument passed in on the command line is %s\n', commandLineArgument);
% msgboxw(['The argument passed in on the command line is ', commandLineArgument]);
if exist(commandLineArgument, 'dir')
% If this folder exists, use it.
handles.imageFolder = commandLineArgument;
fprintf(1, 'Changed image folder to this: %s\n', handles.imageFolder);
else
fprintf(1, 'This folder does not exist, so we cannot change to it:\n %s\n', commandLineArgument);
end
end
fprintf(1, 'handles.imageFolder = %s\n', handles.imageFolder);
end
Adapt it as you see fit.
댓글 수: 2
Image Analyst
2015년 6월 2일
Glad I was able to help. Thanks for getting back to me and Accepting the answer.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!