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.

采纳的回答

Image Analyst
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 个评论
Matt
Matt 2015-6-2
编辑:Matt 2015-6-2
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by