escribiendo un archivo de texto desde MATLAB

I am trying to export a double array from MATLAB into a txt file. I can do this easily but the data is not structured how i need it. I need the data to be structured in the following way in the txt file;

-0.0195
-0.0217
-0.0260
-0.0274
-0.0258
-0.0246
-0.0244
-0.0233
-0.0209
-0.0221

Does anyone know how this would be done using dlmwrite?

preguntado el 09 de marzo de 12 a las 13:03

2 Respuestas

¿Quizás algo como esto?

A=[-0.0195; -0.0217; -0.0260; -0.0274; -0.0258; -0.0246; -0.0244; -0.0233; -0.020;-0.0221];
dlmwrite('example.txt', A, 'newline', 'pc')

The last two argument determines the new line character used (CR or CR+LF), depending on the platform. Use 'pc' for the Windows version, and 'unix' para todos los demás.

For full cross-platformness, you can use the isunix function, and have something like the following preceding your code:

if isunix==true
   platform='unix'
else
   platform='pc'
end

y luego usar el platform variable as the last argument in dlmwrite.

respondido 09 mar '12, 13:03

thanks for your answer, i have tried that and it still does not structure the data how i need it, in a single column. There are a huge amount of lines in the array to write to txt file. - Mike Allen

@MikeAllen: You have to make sure your array is a column vector. If not, adjust as necessary. Make a simple example and show precisely what input do you use, and what output do you expect. - mente corrosiva

If your data is in a row-vector called A this will write it into a column in afile.txt:

dlmwrite('afile.txt',A,'\n')

respondido 09 mar '12, 13:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.