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
Customizing Plots : There are numerous ways to customize figures in the Figure Window. On clicking the Plot Tools icon will bring up the Property Editor & Plot Browser, with ma

Illustration of a recursive function: illustration is of a recursive function which does not return anything, but simply prints. The below function prtwords receives a sentenc

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

If I have a vector representing the packed storage form of a symmetric matrix, how do I perform a cholesky factorisation on that?

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,

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

Built-in function for Differentiation: The MATLAB has a built-in function, diff that returns the differences between consecutive elements in a vector. For illustration, >>

Differentiation: The derivative of a function y = f(x) can be written as follows or f  '(x) and is defined as the rate of change of the dependent variable y with respe

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

Symbolic Expression The solve function solves an equation and returns the solution(s) as symbolic expressions. The answer can be converted to numbers by using any numeric funct