How to pass inputs to compiled matlab function with internal input statements?

4 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 1 Jun 2015
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 Comments
Matt
Matt on 2 Jun 2015
Edited: Matt on 2 Jun 2015
The original function had no arguments, just the input prompts, so it would just die. There was no varargin. I switched to using varargin and everything is happy now.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!