MATLAB: How to pass inputs to compiled matlab function with internal input statements

command linecompilerinputMATLAB

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.

Best Answer

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.
Related Question