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
Error-checking for integers: illustrations of running this script as shown below: >> readoneint Enter an integer: 9.5 Invalid! Enter an integer: 3.6 Invalid

Example of Recursive functions: This definition is recursive as a factorial is defined in terms of the other factorial. There are two parts to any recursive definition: the co

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

strvcat function - concatenation: The function strvcat will concatenate it vertically, that means that it will generate a column vector of the strings.   >> strvcat(fir

Illustration of nested function: The output arguments are distinct from variables. The scope of an output argument is merely the nested function; and it cannot be used in the

Dimensions - matrix: The size and length functions in the MATLAB are used to find array dimensions. Length function returns the number of elements in the vector. The size func

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

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

Three-dimensional pie and bar: For the bar3 function, x & y vectors are passed and the function displays three-dimensional bars as shown in figure: Figure: Three-dimen

Use of string variables: The Characters involve letters of the alphabet, punctuation marks, digits, white space, and control characters. The Control characters are characters