How to put a vector in a file?

I'd like to create a vector from 1 to 744 (vertically) and put that in a file .txt
1
2
3
..
..
744
Thanks

 Respuesta aceptada

Stephen23
Stephen23 el 14 de Feb. de 2018
Editada: Stephen23 el 14 de Feb. de 2018

2 votos

[fid,msg] = fopen('filename.txt','wt');
assert(fid>=3,msg)
fprintf(fid,'%d\n',1:744)
fclose(fid);
Or
V = 1:744;
dlmwrite('filename.txt',V(:),'newline','pc')

2 comentarios

Bruno Souza
Bruno Souza el 19 de Feb. de 2018
Dear, is possible to put the zeros before? Like this:
001
002
003
004
005
006
007
008
009
010
011
...
Stephen23
Stephen23 el 20 de Feb. de 2018
Editada: Stephen23 el 20 de Feb. de 2018
Of course, just use an appropriate format string:
fprintf(fid,'%03d\n',1:744)
Read the fprintf help for more information on format strings.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Feb. de 2018

Editada:

el 20 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by