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
Give the formula for a rational function that has a hole at x=7 & vertical asmptote at x=-3/2

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

Example of Minimum and Maximum Value For matrices, the functions min and max operate column wise by the default: >> mat = randint(2,4,[1 20]) mat =    9   10   1

Example of Logical built-in functions: For equivalent to all the function, we should make sure that the entire elements in the vector are logically true. The one way of doing

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

Illustration of Empty vectors: The Empty vectors can also be used to delete elements from the arrays. For illustration, to remove the third element from array, an empty vector

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

Strcat function - Concatenation : The strcat function, though, will eliminate the trailing blanks from strings before concatenating. Note that in these illustrations, the trail

Plot types: Besides plot and bar, there are another plot types like stem plots, histograms, stem plots, area plots and pie charts, and also other functions which customize the

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