To save your matlab variables/arrays as ascii text, there are a number of things you can do. Here are some options in order of increasing difficultly:
- For small matrices, you can use the "diary" command to create a diary file, and then list the variables on this file. You can then use your text editor to manipulate the diary file at a later time. The output of the diary includes the matlab commands used during the session. To turn the diary on, you simply enter a command of the form:
To turn the diary off, just enter the command:
When using this method, you have some control the output format with the "format" command. See "help format" for more details.
- You can save variables using the "save" command, with the /ascii option.
creates an ASCII file called temp.dat which contains something like:
The format options are limited to either short or long floating point format with the "save" command.
- Use the "fopen" and "fprintf" commands in Matlab to create your own custom format. These commands are similar to the ANSI C functions of the same name, with some extensions. Here is a simple example from "help fprintf". These statements
create a text file containing a short table of the exponential function: