unix command in for loop

4 visualizaciones (últimos 30 días)
Sean
Sean el 27 de Oct. de 2013
Comentada: Ken Atwell el 27 de Oct. de 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!

Respuestas (2)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by