i want to export data from excel file to text file. in excel there are three columns with three rows first two columns contain fractional numbers with two decimal places, third column contains integers
with this piece of code
A = xlsread ('data_file.xlsx', 'Sheet1', 'A1:C10');
fid = fopen ('output.txt', 'w');
dlmwrite (fid, A, '\t' );
fclose (fid)
in the text file i get string 111.11 22.22 50111.12 22.23 50111.13 22.24 50
how should the code looke like to get this in the text file
111.11 22.22 50
111.12 22.23 50
111.13 22.24 50

 Accepted Answer

If you need a specific format, dlmwrite and friends aren't (your friends, that is)...
fmt=[repmat('%.2f\t',1,2) '%d\n'];
fprintf(fid,fmt,A.')

2 Comments

Thanks for your help (it works) and advice.
No problem; NB: the use of the .' transpose to get output in row-major order...

Sign in to comment.

More Answers (0)

Tags

Asked:

on 20 Jan 2015

Commented:

dpb
on 21 Jan 2015

Community Treasure Hunt

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

Start Hunting!