Writing data to a file, MATLAB Programming

Writing data to a File:

The save function can be used to write a data from the matrix to the data file, or to append a data file. The format is as shown below:

save filename matrixvariablename -ascii

The -ascii qualifier is used when generating a text or data file. The following generates a matrix and then saves the values of the matrix variable to a data file known as the testfile.dat:

>> mymat = rand(2,3)

mymat =

0.4565  0.8214  0.6154

0.0185  0.4447  0.7919

>> save testfile.dat mymat -ascii

This generates a file known as the testfile.dat which stores the numbers

0.4565  0.8214  0.6154

0.0185  0.4447  0.7919

The type command can be used to show the contents of the file; note that the scientific notation is used as shown below:

>> type testfile.dat

4.5646767e-001  8.2140716e-001  6.1543235e-001

1.8503643e-002  4.4470336e-001  7.9193704e-001

Note: When the file already exists, then the save function will overwrite it; save always starts writing from the starting of a file.

Posted Date: 10/18/2012 7:08:35 AM | Location : United States

Related Discussions:- Writing data to a file, Assignment Help, Ask Question on Writing data to a file, Get Answer, Expert's Help, Writing data to a file Discussions

Write discussion on Writing data to a file
Your posts are moderated
Related Questions
Command Window: To the left of the Command Window, there are 2 tabs for the Current Directory Window and Workspace Window. If the Current Directory tab is selected, the files

Need help programming in Matlab for airy equations

Show the output - algorithms: Where does the output go? The two possibilities are (i) to an external file, or (ii) to a window on the screen. Based on system, one of these wil

A file houseafford.dat stores on its three lines years, median incomes and median home prices for a city. The dollar amounts are in thousands. For example, it might look like this:

Example: Load from File and Plot Data: As illustration, a file known as timetemp.dat stores two lines of data. The first line is the time of the day, and the next line is the

Function char: The function char does the opposite; it converts from any number type to the type char: >> char(numequiv) ans = a As the letters of the alphabet are

Micro-mouse is an engineering design competition created by IEEE in the late 1970s. Small robotic "mice" solve a 16x16 cell maze. The mice are completely autonomous and must find t

Rules for variable names: In addition, the variable names must always be mnemonic that means they should make some sense. For illustration, if the variable is storing the radi