Illustration of writing variables to a file, MATLAB in Mathematics

Illustration of Writing variables to a file:

For illustration, in the below session in the Command Window, 3 variables are generated; these are then exhibited using who. Then, the variables are saved to file named 'sess1.mat'. The who function is then used to show the variables stored in that file.

>> mymat = rand(3,5)

mymat =

   0.9501   0.4860   0.4565   0.4447   0.9218

   0.2311   0.8913   0.0185   0.6154   0.7382

   0.6068   0.7621   0.8214   0.7919   0.1763

>> x = 1:6;

>> y = x.^2;

>> who

Your variables are:

mymat x y

>> save sess1

>> who -file sess1

Your variables are:

mymat x y

 

To save only one variable to a file, the format is as shown below:

save filename variablename

 

For illustration, only the matrix variable mymat is saved in a file known as sess2

>> save sess2 mymat

>> who -file sess2

Your variables are:

mymat

 

Posted Date: 10/20/2012 6:42:06 AM | Location : United States







Related Discussions:- Illustration of writing variables to a file, Assignment Help, Ask Question on Illustration of writing variables to a file, Get Answer, Expert's Help, Illustration of writing variables to a file Discussions

Write discussion on Illustration of writing variables to a file
Your posts are moderated
Related Questions
Animation: In this part we will observe a couple of ways to animate a plot. These are visuals, therefore the outcomes can't really be shown here; it is essential to type these

Pie chart - plot functions: The MATLAB also has a function pie which will generate a pie chart. Calling the function with the form pie (vec) draws a pie chart, by using the pe

Types of User-defined Functions: We know how to write a user-defined function, stored in an M-file, which computes and returns one value. This is merely one type of the functi

Print an imaginary number: To print an imaginary number, the function disp will show both parts automatically: >> disp(z1)    4.0000 + 2.0000i The function fprint

Sorting The Sorting is a process of putting a list in order; either in descending (maximum to minimum), or ascending (minimum to maximum) order. For illustration, here is a li

Error-Checking for Integers: As MATLAB uses the type double by default for all the values, to check to make confirm that the user has entered an integer, the program have to c

Illustration of Labels and prompts: The program below prompts the user for endpoints (x1, y1) and (x2, y2) of a line segment, and computes the midpoint of the line segment, th

Changing Dimensions: In addition to transpose operator, the MATLAB has some built-in functions which change the dimensions or configuration of matrices, involving fliplr, resh

Illustration of Variance For illustration, for the vector [4, 6, 1, 5], there are n = 4 values therefore n - 1 is 3. The mean of this data set is also 4. The variance will be

Writing to Files: There are many lower level functions which can write to files. We will focus on the fprintf function that can be used to write a file and also to append to a