Copyfile without overwriting
Mostrar comentarios más antiguos
Hello!
How can I copy the content of a *.m file in another. I used copyfile('1.m','2.m') but with this command the content of 2.m will be overwriten by the content of 1.m.
Ex: 1.m content: test1; 2.m content: test 2. I am expecting to get after using copyfile the content of 2.m like: test 2, test1.
I also used the next lines but it is not looking ok.. % fid = fopen('first.m'); % F= fread(fid, '*char')'; % fclose(fid);
Thanks!
Respuesta aceptada
Más respuestas (1)
Sean de Wolski
el 28 de Feb. de 2012
0 votos
You could use fwrite, or fprintf to write to the end of the file, fgetl would also be your friend.
6 comentarios
Diana Acreala
el 28 de Feb. de 2012
Honglei Chen
el 28 de Feb. de 2012
To use all of these you need to use fopen first to open the file. You can open your 1.m in 'r' mode and 2.m in 'a' mode. You can then get each line from 1.m using fgetl and write them to 2.m using fwrite or fprintf.
Diana Acreala
el 28 de Feb. de 2012
Diana Acreala
el 28 de Feb. de 2012
Honglei Chen
el 28 de Feb. de 2012
I added an example in my answer above
Diana Acreala
el 28 de Feb. de 2012
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!