Sprintf function, MATLAB in Mathematics

Assignment Help:

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.


Related Discussions:- Sprintf function

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

Function isreal - complex numbers, Function isreal - complex numbers: ...

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

Dimensions - matrix, Dimensions - matrix: The size and length function...

Dimensions - matrix: The size and length functions in the MATLAB are used to find array dimensions. Length function returns the number of elements in the vector. The size func

Use of logical vector, Use of logical vector: Determine how many eleme...

Use of logical vector: Determine how many elements in the vector vec were greater than 5, the sum function can be used on the resulting vector isg: >> sum(isg) ans =

Logical vectors, Logical Vectors: The relational operators can also be...

Logical Vectors: The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each eleme

Find minimum and maximum for each row, Find Minimum and Maximum for each ro...

Find Minimum and Maximum for each row To find the maximum (or minimum) for each row, the dimension of 2 (that is how a MATLAB refers to rows) can be identified as the third arg

Nested if-else statements, Nested IF-ELSE statements: The if-else stat...

Nested IF-ELSE statements: The if-else statement is used to select between the two statements. In order to select from more than two statements, the if-else statements can als

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,

Writing variables to a file, Writing variables to a File: The save com...

Writing variables to a File: The save command is used to write variables to a file, or to append the variables to a MAT-file. By the default, save function writes to a MAT-fil

Error-checking for integers, Error-Checking for Integers: As MATLAB us...

Error-Checking for Integers: As MATLAB uses the type double by default for all the values, to check to make confirm that the user has entered an integer, the program have to c

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