I would like to use fprintf to save the following line as a text file.
%%number of points: x
x is a variable and for instance x=25
%%number of points: 25
thank you very much

2 comentarios

Adam
Adam el 13 de Jun. de 2016
And what aspect of it is causing you a problem?
Maryam Hamrahi
Maryam Hamrahi el 13 de Jun. de 2016
I do not know how to write it

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Jun. de 2016

0 votos

fid=fopen('your_file.txt','w')
x=25
str=sprintf('number of points: %d',x)
fprintf(fid,'%s',str)
fclose(fid)

4 comentarios

Maryam Hamrahi
Maryam Hamrahi el 13 de Jun. de 2016
Many thanks.
It should be like this:
%% number of points: 25
Azzi Abdelmalek
Azzi Abdelmalek el 13 de Jun. de 2016
Editada: Azzi Abdelmalek el 13 de Jun. de 2016
fid=fopen('your_file.txt','w')
x=25
str=sprintf('%%%%number of points: %d',x)
fprintf(fid,'%s',str)
fclose(fid)
Maryam Hamrahi
Maryam Hamrahi el 13 de Jun. de 2016
thanks a lot
Walter Roberson
Walter Roberson el 13 de Jun. de 2016
I would just go for
fid = fopen('your_file.txt', 'w');
x = 25;
fprintf(fid, '%%%%number of points: %d\n', x);
fclose(fid);

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 13 de Jun. de 2016

Comentada:

el 13 de Jun. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by