dlmwrite creates an extra empty line - how do i remove it?

1 visualización (últimos 30 días)
Michelle Johnson
Michelle Johnson el 3 de Nov. de 2016
Comentada: Walter Roberson el 4 de Nov. de 2016
hi all I have a proprietary file which holds a 3X93 integer matrix. I want to save it as a text file using dlmwrite. It loads correctly the file and when i save the data as a text file using dlmwrite it correctly saves the 3X93 elements but also adds a fourth line with an empty space. this empty space messes up the following processing i need to do on this text file. any idea on how to avoid the creation of this extra space or any suggestions for a further step to remove it from the text file?
thanks so much!

Respuestas (1)

Walter Roberson
Walter Roberson el 3 de Nov. de 2016
My suspicion is that what you are noticing is that dlmwrite() ends the last line with standard end-of-line characters (see the 'newline' option for which end-of-line it uses). Often that is the Right Thing To Do, but sometimes it confuses input processing that expects the end of file at the end of the last valid line instead of at the beginning of what would be the next line.
If that is what is happening, then you will need to do the fopen/fprintf/fclose yourself, or you will need to use some process that removes the final end-of-line. Or you will need to fix the processing of the files to take this into account.
There is another possibility which should morally be completely obsolete but is not completely gone yet, which is that the old DOS way of signaling end of file was not by the file headers storing information about how big the file is, but rather by there being an end-of-file character, ascii position 26, control-Z, stored in the file. If present that can look like an extra line if the files are not read in DOS mode. I don't think dlmwrite creates such files, but I have not tested to be sure.
  4 comentarios
Michelle Johnson
Michelle Johnson el 4 de Nov. de 2016
thank you so much!! i really appreciate this! one final question - what is the itemfmt variable supposed to be? you do not define it anywhere. am i missing here something? thanks again!
Walter Roberson
Walter Roberson el 4 de Nov. de 2016
Sorry, that should be precision instead of itemfmt

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by