Illustration of writing to files, MATLAB in Mathematics

Assignment Help:

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


Related Discussions:- Illustration of writing to files

Sorting, Sorting The Sorting is a process of putting a list in order; ...

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

Standard deviation, Standard Deviation The standard deviation is the sq...

Standard Deviation The standard deviation is the square root of variance: The built-in function in a MATLAB for the standard deviation is known as std; the standard dev

Changing dimensions, Changing Dimensions: In addition to transpose ope...

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 logical vectors, Illustration of Logical vectors: Call...

Illustration of Logical vectors: Calling the function appears to return similar vector as simply vec > 5, and summing the result still works to determine how many elements wer

Illustration of writing variables to a file, Illustration of Writing variab...

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,

Recursive functions, Recursive Functions: The Recursion occurs wheneve...

Recursive Functions: The Recursion occurs whenever something is defined in terms of itself. In the programming, a recursive function is a function which calls itself. The Recu

Built in recursive function in matlab, Built in recursive function in MATLA...

Built in recursive function in MATLAB: We have seen that the built-in function in MATLAB to compute factorials, termed as the factorial and we know how to implement the iterat

Bar and barh functions - plot functions, bar and barh functions: For a...

bar and barh functions: For a matrix, the bar and barh functions will group altogether the values in each and every row. The illustration is as shown: rm = randint(2,4,[1

Built-in functions for complex numbers, Built-in functions for Complex numb...

Built-in functions for Complex numbers:   We know that in MATLAB both i and j are built-in functions which return √-1 (therefore, they can be thought of as built-in constants).

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd