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
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

Histogram: The histogram is a particular type of bar chart which shows the frequency of occurrence of the values within a vector. The Histograms use what are known as bins to

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

User input in the while loop: Here is an illustration of running this script: >> readonenum Enter a positive number: -5 Invalid! Enter a positive number: -2.2

Example of Symbolic Expression When there is more than one variable, the MATLAB selects which to solve for. In the illustration below, the equation ax 2 + bx = 0 is solved. Th

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

Complex numbers: A complex number is commonly written in the form z = a + bi here a is known as the real part of the number z, b be the imaginary part of z, and i is √-1

Refer the subset of a matrix: It is also possible to refer to the subset of a matrix. For illustration, this refers to the first & second rows, second & third columns: >> m

Illustration of Minimum and Maximum Value Both of these functions also return the index of the minimum or maximum value; when there is more than one occurrence, it returns 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