unix command in for loop

4 ビュー (過去 30 日間)
Sean
Sean 2013 年 10 月 27 日
コメント済み: Ken Atwell 2013 年 10 月 27 日
I'm trying to execute a shell command using the unix command within a for loop. The first part of the code deals with dumping a list of files into a .txt file named firstfile.txt. The part that is giving me trouble is specifically in the unix command portion of the code. The code is below.
filename=importdata('firstfiles.txt'); %importing list of files as an array
filename1=char(filename); %converting to character
for 1:length(filename);
filename2=filename1(i);
command1='simpleTranslate -z --outstyle=2 -q0 -n5000 filename2 > test.txt';
[x,y]=unix(command1);
more code that isn't relevant to this problem % code
end
The simpleTranslate portion of the command1 is a custom linux code that I'm calling on, but the primary problem is the filename2 variable. I don't know how to get the unix command to step through each file name within the filename2 array. Any insights into this problem would be very appreciated. Thanks!

回答 (2 件)

Ken Atwell
Ken Atwell 2013 年 10 月 27 日
Your command line being sent to unix() includes the string 'filename2', not the value of filename2. Try:
command1= ['simpleTranslate -z --outstyle=2 -q0 -n5000 ' filename2 ' > test.txt'];

Sean
Sean 2013 年 10 月 27 日
Thanks! that helped alot!
  1 件のコメント
Ken Atwell
Ken Atwell 2013 年 10 月 27 日
Glad to hear it, please accept the answer. :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by