フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

can change the name of txt. file not manually

1 回表示 (過去 30 日間)
huda nawaf
huda nawaf 2013 年 4 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
hi,
I have to run the following code sevral times, each time I have to change the name of files , I have to read 2 files and write one file. If I change the name of files manually , it takes long time . Are there a way by which can change the name not manually . i.e can do that x=2; in this case I change just x each running
f1=dlmread('d:\matlab\r2011a\bin\new_movielens1\netflix\sequences\part1_x.txt');
f4=dlmread('d:\matlab\r2011a\bin\new_movielens1\netflix\sequences\intersect_x.txt');
[p o]=size(f1);k=1;
for i=1:length(f4)
seq1(i,:)=f1(f4(i),:);
seq2(i,:)=f2(f4(i),:);
seq3(i,:)=f3(f4(i),:);
end
dlmwrite('d:\matlab\r2011a\bin\new_movielens1\netflix\sequences\com_eval_x.txt',seq3);
thanks in advance

回答 (1 件)

Ahmed A. Selman
Ahmed A. Selman 2013 年 4 月 6 日
If your filenames are part1_1.txt, part1_2.txt, part1_3.txt.. etc.,
and intersect_1.txt, intersect_2.txt.. etc.,
and want to write in files as com_eval_1.txt, com_eval_2.txt..etc., respectively,
use the following method:
name1='d:\matlab\r2011a\bin\new_movielens1\netflix\sequences\part1_';
name2='d:\matlab\r2011a\bin\new_movielens1\netflix\sequences\intersect_';
nameout='d:\matlab\r2011a\bin\new_movielens1\netflix\sequences\com_eval_';
ext='.txt';
n=... ;% number of files
for x=1:n
F1_name=[name1,num2str(x),ext];
F4_name=[name2,num2str(x),ext];
OutName=[nameout,num2str(x),ext];
f1=dlmread(F1_name);
f4=dlmread(F4_name);
[p o]=size(f1);k=1;
for i=1:length(f4)
seq1(i,:)=f1(f4(i),:);
seq2(i,:)=f2(f4(i),:);
seq3(i,:)=f3(f4(i),:);
end
dlmwrite(OutName,seq3);
end
  1 件のコメント
huda nawaf
huda nawaf 2013 年 4 月 6 日
Many thanks , I will try that

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by