Save as separate file with separate name in txt

2 visualizaciones (últimos 30 días)
Vania krm
Vania krm el 5 de Mzo. de 2019
Comentada: Geoff Hayes el 6 de Mzo. de 2019
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 comentarios
Vania krm
Vania krm el 6 de Mzo. de 2019
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 el 6 de Mzo. de 2019
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

Iniciar sesión para comentar.

Respuestas (1)

darova
darova el 5 de Mzo. de 2019
s = num2str(c(i));
save(['/Users/desktop/' s '.txt'], 'f1');

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by