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 CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by