Hi.
-i am not the most experienced matlab programer how ever, i am trying to exploite an batch script that i have previously writen.
by using uigetfile i will get an array of file names in Filnames i.e test.txt test2.txt test3.txt
i wish to pass this along to the batch script. and have tried !C:\test.bat Filnames(:,1) Filnames(:,2) Filnames(:,3)
but the batch script only recive the text as above: Echo Filnames(:,1) ......
any solultion to pass the found filname to an batch script ?

답변 (3개)

per isakson
per isakson 2013년 5월 11일

0 개 추천

I would do it this way
cmd = sprintf( 'c:\\test.bat %s %s %s', file(:,1), file(:,2), file(:,3) );
msg = dos( cmd );
because that allows me to inspect cmd. I can even copy&paste cmd to the Command Prompt and check that it works.
Replace dos by system if you are on Unix.

댓글 수: 2

Aleksander
Aleksander 2013년 5월 12일
This is an possible solution. however since my code is per now like this:
[Filename,Filepath] = uigetfile({'*.txt','LOG FILES,(*.txt)'},'SELECT LOG FILE(S)','C:\','Multiselect','on')
-when you select multiple files thee filenames are resturned in an cell array, which sprintf does not accept.
i am considering to drop the file names in an text file using dlmwirte and then have the batch file read the text file.
per isakson
per isakson 2013년 5월 12일
I just copied from the code you showed.
Either you handle the list of files in the bat-file or in Matlab, whichever is more convenient.

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

Image Analyst
Image Analyst 2013년 5월 11일

0 개 추천

댓글 수: 3

Aleksander
Aleksander 2013년 5월 12일
Thanks. seens intresting, all do not sure directly how to implement it, as i want to use "uigetfile". al do i ihave thought about an function where the user only points to a folder an all files within are processed.
Image Analyst
Image Analyst 2013년 5월 12일
편집: Image Analyst 2013년 5월 12일
Try this code, which I adapted from the FAQ by inserting your code before it:
startingFolder = fullfile(matlabroot, '\toolbox\images\imdemos');
[baseFileNames, chosenFolder] = uigetfile({'*.*','All Files,(*.*)'},'SELECT LOG FILE(S)',...
startingFolder,'Multiselect','on')
for k = 1:length(baseFileNames)
baseFileName = baseFileNames{k};
fullFileName = fullfile(chosenFolder, baseFileName);
message = sprintf('Now processing %s', fullFileName);
fprintf('\n%s\n', message);
promptMessage = sprintf('%s\n\nDo you want to Continue processing,\nor Cancel to abort processing?', message);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
end
Aleksander
Aleksander 2013년 5월 22일
hi. thanks for the help :) this is the solution i came up with.
% code
[Filenames,Filepath] = uigetfile({'*.*','LOG FILES ,(*.*)'},'SELECT... LOGFILE(S)','C:\','Multiselect','on');
m = max(size(Filenames));
mm = (m)-1
%print single filname only:
if (m==11)
basefilename = [Filenames]
else
%print several found file names to a text file.
Filenames = sort(Filenames);
basefilename = [''] ;
for k = 1:length(Filenames);
Filename = Filenames{k};
if (mm==(k)-1)
basefilename = [basefilename Filename];
else
basefilename = [basefilename Filename '+'];
end
end
end

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

Maria Sheeba
Maria Sheeba 2017년 3월 9일

0 개 추천

How to create a batch file in MATLAB for an .exe file??

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2013년 5월 11일

답변:

2017년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by