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

조회 수: 6 (최근 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.
Image Analyst
Image Analyst 2015년 6월 2일
Glad I was able to help. Thanks for getting back to me and Accepting the answer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by