In this post I will give some examples of exporting to different text formats. I will also mention how to import data using complementary commands.
The simplest way to export data to text format is this:
save -asciiMatlab exports data by default in the scientific numeric format. If you want to use these data with some other program outside matlab, this can lead to problems. Although nowadays many programs use libraries that permit reading scientific notation (e.g. boost regex library for C++), it is sometimes better to write to a fixed-digits format.
Using
save, the -double option says that you want the numbers in 16-digit format. To write matrix A to a column separated value (CSV) file, there are several alternatives.
dlmwrite is one possibility:>>
dlmwrite('attr20.ascii',A,'delimiter',',');The default delimiter is already the comma, so the last parameter is unnecessary. If you want your data space-separated this command is your friend:
>>
dlmwrite('attr20.ascii',A,'delimiter','\t');If you use the tabulator as delimiter, you can use also use
save:>> save('attr20.ascii','A','-ascii','-double','-tabs');The last option I give here is
csvwrite:>> csvwrite('attr20.ascii',A); These commands work for vectors and two-dimensional matrices.
Also sometimes useful is
diary to save your command history to a disk file. You can view and edit the resulting text file using any word processor.For importing data to matlab you can use the corresponding commands dlmread, load, csvwrite. Some files you might have to filter before reading them into matlab. For example to get rid of comments. Say the files provide comments at the start of the line starting with the percent sign (%). Then filtering can be done with sed:
>
sed -i /^%/d * Enjoy. Please leave a comment below for questions and suggestions.
[ Read more... ]

