unix command in for loop
4 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
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'];
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!