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 =



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', .  .  .


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

Matrix of Plots: The other function which is very useful with any type of plot is subplot that creates a matrix of plots in the present Figure Window. The three arguments are

Common form of the switch statement: The common form of the switch statement is as shown below:   switch switch_expression   case caseexp1    action1   case cas

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

Strings as Vectors: The Strings are considered as vectors of characters-or in another words, a vector in which each and every element is a single character-so numerous vector

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

Empty Vectors: An empty vector or in another words, a vector which stores no values, can be generated using the empty square brackets: >> evec = [] evec = [] >> lengt

Labels and Prompts: The script loads all the numbers from file into a row vector. It then splits the vector; it stores the initial element that is the experiment number in a v

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

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