4.4

4.4 | 15 ratings Rate this file 28 Downloads (last 30 days) File Size: 10.7 KB File ID: #10243
image thumbnail

saveascii.m v6.2 (Oct 2009)

by

 

06 Mar 2006 (Updated )

Save or display a matrix with given precision, delimiter or format for each (or every) column!

| Watch this File

File Information
Description

Do you still use SAVE -ASCII, DLMWRITE or DISP, NUM2STR?

With this program you can save (or display) your data with a different format and delimiters for every column, given as optional inputs in a user-friendly way (check the screenshot).

If you don't want to deal with the format (things like '%3.1f %13.4f', etc.) you can give only the precision that you want for each (or every) column (i.e. [1 4]) and the program creates the format by itself.

See this example about saving and displaying data with precision as input:

% DATA:
>> c = [ -130.145 45
>> -130.1 45.6789 ];
>> cfile = 'coord.dat';

% SAVING FILE WITH COMMENTED HEADING:
>> saveascii('% My coordinates',cfile)
>> saveascii('% [LON LAT]',cfile,'a')
>> saveascii(c, cfile, 2, 'a')

% VIEWING THE RESULT:
>> edit(cfile)
---------------------------
% My coordinates
% [LON LAT]
-130.15 45.00
-130.10 45.68
---------------------------

% LOADING DATA IGNORING HEADING:
>> c = load(cfile);
c =
 -130.1500 45.0000
 -130.1000 45.6800

% DISPLAYING LOADED DATA:
>> saveascii(c,1,' ') % With only 1 decimal (better than DISP)
-130.2 45.0 % and extra spaces within
-130.1 45.7

% VIEWING THE HEADING WITH readline.m
>> disp(readline(cfile))
% My coordinates
>> disp(readline(cfile,2))
% [LON LAT]

Enjoy it!
Any comments and bugs reports will be very appreciated!

Acknowledgements

This file inspired Readline.M V3.0 (Jun, 2009).

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
12 Jan 2010 Arthur

just what I needed!

05 Nov 2009 Cegeon

Just adding to the positive reviews. It's amazing.

Something that took me 59 seconds to save using dlmwrite took only 8.5 seconds, nearly SEVEN times faster! AND it can append.

26 Aug 2009 Itamar

Hi,

A great code! Works great with my files. Very easy to read and undersatnd. I used to work with matlab dlmwrite, but i found many bugs while saving. I think even that your code is faster than dlmwrite. Saved me a lot of debugging time.
Great job! Thanks for sharing!

11 Mar 2008 Carlos Adrián Vargas Aguilera

New rewriten version 4.0 (see the updates below). Note: must be STR2NUM instead of STR2DOUBLE up here at the description.

05 Feb 2008 Karel Castro

Hola Carlos:
Muchas gracias por tu programa! fue muy util. Yo estudie en la UABC oceanologia y la maestria, ahora estoy en Inglaterra en el doctorado, y mira la sorpresa que me encuentro al buscar lo que necesitaba para mi programa, alguien de CICESE! gracias

06 Oct 2007 Dan Venette

Yes! Thanks! Looking all over for something like this!

26 Sep 2007 Rainer Ng

Just what I needed!

18 Sep 2007 Alex Ping-Feng Chen

great job!!thanks!

20 Jun 2007 Marc S

I had to debug it, but it worked fine. I use Matlab 6.0.0.88 version 12. The logical operators in matlab are single & and |, not the C++ operator notation (&& and ||). The file didn't work until I did a "replace all" (|| -> |, && -> &). Then it worked great. Thanks!

27 Feb 2007 Carlos Adrián Vargas Aguilera

Gracias Emilio! Ya envie la version 3.2. Tenias razon, lo cambie por chars=max(M,[],1);

El autor.

26 Feb 2007 Emilio Velazquez

fantastico! justo el programa que buscaba! gracias FileExchange!

solo tuve problemas con vectores fila y cambie el inicio de la linea 355, por chars=max(M,1);

21 Feb 2007 Carlos Adrian Vargas Aguilera

This is an upgraded version.
a) Now is easier to select the format (only with the decimals!) optional,
b) saves string matrices without specifying the format,
c) there's an optional output, and
d) the output file works fine for any Windows text editors.

Hope you find it useful.

11 Dec 2006 Steven Bedrick

Woohoo! This saved me tons of time. Anybody know why Matlab doesn't have something this useful built right in?

04 Oct 2006 Schilieri Tochiani

A program that every DATA-workman must have!

24 May 2006 David Choi

Works great!!!! Thanks.

NOTE: saveascii will save the numbers in specified format. Matlab's save -ascii will save it in scientific notation only.

09 Mar 2006 Tomas Moon

All data are save with the same specified format. Good! I always tried this with fprint but get the matrix transpose, and here's the solution. Excellent job!

08 Mar 2006 urs (us) schwarz

whilst a nice snippet with good help, it emulates the well-known DLMWRITE
us

08 Mar 2006 Frederic Moisy

Why not using Matlab's SAVE with option '-ascii' ?
(Perhaps this is explained in the help, but it is written in spanish. Ayuda en ingles por favor)

Updates
28 Sep 2006

Now allow different format for each column and separator.

13 Nov 2006

English translation from spanish. Little changes on the submit.

21 Feb 2007

Now with input decimals for floating-point, 'wt' and 'at' for Windows users, output to Command Window and check errors. Some changes on the submit too.

26 Feb 2007

Now accept zero and negative decimals.

01 Mar 2007

Bug fixed by Emilio Velazquez

02 Mar 2007

Bug fixed on get_digits subfunction. Used SUM of logicals instead of ANY.

11 Mar 2008

V4.0: Cleaner and rewritten code (cells), reduced running time and memmory usage, fixed bugs, accounts Inf and NaN's, change default delimiter, change beginner char, added ending option, optionaly format string output.

13 Mar 2008

Fix little bug with INTEGER type. Changes on the submition.

13 Mar 2008

Fixed bug with not numeric elements (NAN's, Inf's and -Inf's).

08 Jun 2009

V5.0 Rewritten help and code. Fixed minor bugs related with empty X. No more reversed outputs. No more Beginning and Ending string optional inputs allowed. No more inputs separated by commas. New overwrite optional warning.

19 Jun 2009

1) Fixed SPRINTF and FPRINTF BUG with negative awful zeros!!!, like '-0.000'.
2) Modified description and screenshot above.
3) Fixed years problem on license.txt.

30 Sep 2009

v6.0 Now saves cells of strings. Fixed bug with string delimiter input.

03 Oct 2009

v6.1 Ignores empty optional inputs. Added some comments.

30 Oct 2009

v6.2 Fixed small bug with parse inputs. Now creates file directory if not exist.

30 Oct 2009

Small mistake in submission name.

Contact us