How can i Pass a file name as input or argument to matlab standalone executable

조회 수: 10 (최근 30일)
My Matalab code reading inputs from '.csv' files. These files will be generated from 'data manager'. here the issue is, file name and file locations will be different every time when data manager runs ( This is to avoid the clash) So, The compiled matlab(EXE) needs to be able to run in any folder and take input file as an argument.
help me in resolving this .... Thanks Sunil Patil

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 7일
Often this would be handled with uigetfile() for interactive file selection. However, taking a filename as an argument has its advantages.
The function that you designate as the "main" one to compile should accept varargin . When nargin > 0 then each varargin{K} is a string that was passed on the command line. For example,
function managedata(varargin)
if nargin > 1
filename = varargin{1};
pathstr = cd();
else
[filename, pathstr] = uigetfile('Which file?');
end
fullname = fullfile(pathstr, filename);
  댓글 수: 2
Sunil Patil
Sunil Patil 2015년 8월 7일
편집: Sunil Patil 2015년 8월 7일
Thanks for your replay.. But Here, Data manger create a temporary folder to run the Matlab EXE for each run and it will be different for each run to prevent any clashes ... So, My matlab exe should take that argument as input @ every run And There won't be user interface to select file location & name.
And,: Matlab exe shold read the '.bat' files which are generated from 'Data manager' and take those argument as input to search 'input file'
Walter Roberson
Walter Roberson 2015년 8월 7일
function managedata(batfilename, varargin)
if ~exist(batfilename, 'file')
error because file does not exist
end
fid = fopen(batfilename,'rt');
while true
thisfile = fgetl(fid);
if ~ischar(thisfile); break; end %end of file
%now process thisfile
end
fclose(fid);

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

카테고리

Help CenterFile Exchange에서 Files and Folders에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by