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
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Files and Folders についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!