unix command in for loop

4 views (last 30 days)
Sean
Sean on 27 Oct 2013
Commented: Ken Atwell on 27 Oct 2013
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!

Answers (2)

Ken Atwell
Ken Atwell on 27 Oct 2013
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 on 27 Oct 2013
Thanks! that helped alot!
  1 Comment
Ken Atwell
Ken Atwell on 27 Oct 2013
Glad to hear it, please accept the answer. :)

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!