Illustration of writing to files, MATLAB in Mathematics

Illustration of Writing to files:

Here is the other illustration in which a matrix is written to a file. At First, an arbitrary 2 × 4 matrix is generated, and then it is written to the file by using the format string %d %d\n', that means that each column from the matrix will be written as an individual line in the file.

>> mat = randint(2,4,[5 20])

mat =

    20   14   19   12

     8   12   17    5

>> fid = fopen('randmat.dat','w');

>> fprintf(fid,'%d %d\n',mat);

>> fclose(fid);

 

As this is a matrix, the load function is used to read it in.

>> load randmat.dat

>> randmat

randmat =

   20   8

   14   12

   19   17

   12   5

>> randmat'

ans =

   20   14   19   12

    8   12   17    5

 

Transposing the matrix will show in the form of the original matrix. When you want this to start with, the matrix variable mat can be transposed before using the fprintf to write to the file. (Obviously, it would be much easier in this situation to just use save rather than!)

Posted Date: 10/20/2012 6:33:18 AM | Location : United States







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

Write discussion on Illustration of writing to files
Your posts are moderated
Related Questions
Structure Consisting of the Fields A MATLAB can also solve the sets of equations. In this illustration, the solutions for x, y, & z are returned as a structure consisting of th

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

Plot types: Besides plot and bar, there are another plot types like stem plots, histograms, stem plots, area plots and pie charts, and also other functions which customize the

Illustration of Empty vectors: The Empty vectors can also be used to delete elements from the arrays. For illustration, to remove the third element from array, an empty vector

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

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

If I have a vector representing the packed storage form of a symmetric matrix, how do I perform a cholesky factorisation on that?

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,

sprintf function: The sprintf function works precisely like the fprintf function, but rather than printing it generates a string. Here are some illustrations in which the outp

Find Minimum and Maximum for each row To find the maximum (or minimum) for each row, the dimension of 2 (that is how a MATLAB refers to rows) can be identified as the third arg