Mike Allen
Mike Allen

Reputation: 1

writing text file from 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?

Upvotes: 0

Views: 816

Answers (2)

mindcorrosive
mindcorrosive

Reputation: 726

Maybe something like this?

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' for all others.

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

and then use the platform variable as the last argument in dlmwrite.

Upvotes: 1

High Performance Mark
High Performance Mark

Reputation: 78306

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')

Upvotes: 0

Related Questions