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
Illustrations of Variable number of output arguments: In the illustrations shown here, the user should actually know the type of the argument in order to establish how many va

Illustration of Spreadsheet Files: This reads the numbers in a double vector variable nums and the text in a cell array txt (the xlsread function forever returns the numbers f

Script a MATLAB program which meets the following speci cations: The program expects an input of a two-variable real-valued continuous function f : R^2--> R The program is to cal

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

Give the formula for a rational function that has a hole at x=7 & vertical asmptote at x=-3/2

Nested IF-ELSE statements: The if-else statement is used to select between the two statements. In order to select from more than two statements, the if-else statements can als

Plot Functions: Faraway, we have plotted to generate two-dimensional plots and bar to generate bar charts. We have seen how to clear the Figure Window by using clf, and how to

Polar Form: Any complex number z = a + bi can be thought of as a point (a,b) or vector in the complex plane in which the horizontal axis is the real part of z, and the vertica

fprintf function - File function: The fprintf function really returns the number of bytes which was written to the file, therefore if you do not want to see that number, suppr

Illustration of logical built-in functions: The function find returns the indices of a vector which meet certain criteria. For illustration, to find all the elements in a vect