Borrar filtros
Borrar filtros

Save a .txt file in a specific folder

28 visualizaciones (últimos 30 días)
Alejandro Estudillo
Alejandro Estudillo el 15 de Mayo de 2018
Comentada: Xavier Aguas el 29 de Mayo de 2020
I have a very simple program. As you can see this program asks for two inputs and store the values in txt file.
ParticipantID = input ('Please, enter your initials ', 's');
ParticipantAge = input ('Please, enter your age ', 's');
fileID = fopen([ParticipantID '.txt'],'at');
header = ['ID\t' 'Age\n'];
Participant_info =[ParticipantID '\t' ParticipantAge '\n'];
fprintf(fileID,Participant_info);
The text file is saved in the folder where the .m file is but I would like to save the text in a subfolder that I have created (let's say 'info'). Any idea about how to do this?
Thanks!

Respuesta aceptada

Lucien Robinault
Lucien Robinault el 15 de Mayo de 2018
Hello, You can just concatenate the path and the name of the file like this :
ParticipantID = input ('Please, enter your initials ', 's');
ParticipantAge = input ('Please, enter your age ', 's');
savePath = './Data/'; % Put the string of the path you want to save your file in
fileID = fopen([savePath ParticipantID '.txt'],'at'); % Concatenate the string
header = ['ID\t' 'Age\n'];
Participant_info =[ParticipantID '\t' ParticipantAge '\n'];
fprintf(fileID,Participant_info);
  2 comentarios
Alejandro Estudillo
Alejandro Estudillo el 16 de Mayo de 2018
This works perfect! Thanks a lot!
Xavier Aguas
Xavier Aguas el 29 de Mayo de 2020
Thanks !

Iniciar sesión para comentar.

Más respuestas (0)

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