Save as separate file with separate name in txt

2 ビュー (過去 30 日間)
Vania krm
Vania krm 2019 年 3 月 5 日
コメント済み: Geoff Hayes 2019 年 3 月 6 日
ds=dataset(xlsfile,prov.xlsx);
f1=ds.rem(1:451);
f2=ds.name(1:451);
for i=1:451
if f1(i)==1
%name
c(i)=f2(i);
save('/Users/desktop/c(i)' '.txt','f1')
end
end
I want to have all 1 values in separate file with special name.
  8 件のコメント
Vania krm
Vania krm 2019 年 3 月 6 日
Thank you very-very much.
Because I want to have all TXT separately for the next step of our works.
I used sprintf but the error is:
Error using save
Cannot create '49.txt' because
'/Users/Desktop/myfolder/0.txt/Users/Desktop/myfolder/102.txt/Users/Desktop/myfolder'
does not exist.
Error in savetxt (line 8)
save(sprintf('/Users/Desktop/myfolder/%d.txt',f2(i),'f1'))
Geoff Hayes
Geoff Hayes 2019 年 3 月 6 日
Vania - I don't understand why you are getting a string like '/Users/Desktop/myfolder/0.txt/Users/Desktop/myfolder/102.txt/Users/Desktop/myfolder' which appears to be a concatenation of several attempts to create files. You may need to post more of your code or try moving the sprintf out of the save to get something like
for i=1:451
if f1(i)==1
%name
c(i)=f2(i);
filename = sprintf('/Users/desktop/%d.txt', f2(i));
save(filename,'f1')
end
end

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

回答 (1 件)

darova
darova 2019 年 3 月 5 日
s = num2str(c(i));
save(['/Users/desktop/' s '.txt'], 'f1');
  1 件のコメント
Vania krm
Vania krm 2019 年 3 月 5 日
But I need to save with different s each time.

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

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by