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:
>> 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:
% My coordinates
% [LON LAT]
% LOADING DATA IGNORING HEADING:
>> c = load(cfile);
% DISPLAYING LOADED DATA:
>> saveascii(c,1,' ') % With only 1 decimal (better than DISP)
-130.2 45.0 % and extra spaces within
% VIEWING THE HEADING WITH readline.m
% My coordinates
% [LON LAT]
Any comments and bugs reports will be very appreciated!
just what I needed!
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.
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!
New rewriten version 4.0 (see the updates below). Note: must be STR2NUM instead of STR2DOUBLE up here at the description.
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
Yes! Thanks! Looking all over for something like this!
Just what I needed!
I had to debug it, but it worked fine. I use Matlab 18.104.22.168 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!
Gracias Emilio! Ya envie la version 3.2. Tenias razon, lo cambie por chars=max(M,,1);
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);
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.
Woohoo! This saved me tons of time. Anybody know why Matlab doesn't have something this useful built right in?
A program that every DATA-workman must have!
Works great!!!! Thanks.
NOTE: saveascii will save the numbers in specified format. Matlab's save -ascii will save it in scientific notation only.
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!
whilst a nice snippet with good help, it emulates the well-known DLMWRITE
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)
Small mistake in submission name.
v6.2 Fixed small bug with parse inputs. Now creates file directory if not exist.
v6.1 Ignores empty optional inputs. Added some comments.
v6.0 Now saves cells of strings. Fixed bug with string delimiter input.
1) Fixed SPRINTF and FPRINTF BUG with negative awful zeros!!!, like '-0.000'.
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.
Fixed bug with not numeric elements (NAN's, Inf's and -Inf's).
Fix little bug with INTEGER type. Changes on the submition.
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.
Bug fixed on get_digits subfunction. Used SUM of logicals instead of ANY.
Bug fixed by Emilio Velazquez
Now accept zero and negative decimals.
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.
English translation from spanish. Little changes on the submit.
Now allow different format for each column and separator.