Sprintf function, MATLAB in Mathematics

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 output is not suppressed and hence the value of the string variable is shown:

 

>> sent1 = sprintf('The value of pi is %.2f', pi)

sent1 =

The value of pi is 3.14

>> sent2 = sprintf('Some numbers: %5d, %2d', 33, 6)

sent2 =

Some numbers:    33,  6

>> length(sent2)

ans =

23

 

In the illustration below, on the other hand, the outcome of the assignment is suppressed; therefore the string is generated including an arbitrary integer and stored in the string variable. Then, few exclamation points are concatenated to that string.

>> phrase = sprintf('A random integer is %d', .  .  .

randint(1,1,[5,10]));

>> strcat(phrase, '!!!')

ans =

A random integer is 7!!!

 

All the conversion specifiers which can be used in the fprintf function can also be used in the sprintf function.

Posted Date: 10/20/2012 5:08:11 AM | Location : United States







Related Discussions:- Sprintf function, Assignment Help, Ask Question on Sprintf function, Get Answer, Expert's Help, Sprintf function Discussions

Write discussion on Sprintf function
Your posts are moderated
Related Questions
Minimum and Maximum Value The MATLAB has built-in functions for numerous statistics. For illustration, min and max to find the minimum or maximum value in a data set. >> x

how can reconstruct just part of an image using imreconstruct?

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

5 p2+8p+15, 3 p2-3p-18, 12 p2-p-30

Indexed empty matrix: The Individual elements cannot be eliminated from matrices, as matrices always have the similar number of elements in every row. >> mat = [7 9 8; 4 6

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

Function isreal - complex numbers: The function isreal returns 1 for logical true when there is no imaginary part of the argument, or 0 for false when the argument does have a

Function xlsread - file function: The function xlsread will read from the spreadsheet file. For illustration, to read from file just generated: >> ssnums = xlsread('ranexc

Referring to and Modifying the Matrix Elements: To refer to matrix elements, the row and then the column indices are given in parentheses (always the row index initially and t

Pie chart - plot functions: The MATLAB also has a function pie which will generate a pie chart. Calling the function with the form pie (vec) draws a pie chart, by using the pe