Converting between the string and number types, MATLAB in Engineering

Converting between the String and Number types:

The MATLAB has many functions which convert numbers to strings in which each character element is a separate digit, and vice versa. (Note: these are distinct from the functions char, double, etc., which convert the characters to ASCII equivalents and vice versa.)

To convert numbers into strings, the MATLAB has functions int2str for integers and num2str for real numbers (that also works with the integers). The function int2str would convert, for illustration, the integer 4 to the string '4'.

 

>> rani = randint(1,1,50)

rani =

38

>> s1 = int2str(rani)

s1 =

38

>> length(rani)

ans =

1

>> length(s1)

ans =

2

 

The rani variable is a scalar that stores one number, while s1 is a string which stores two characters, '3' and '8'.

Even though the answer of the first two assignments is 38, note that the indentation in the Command Window is distinct for the number and the string.

Posted Date: 10/20/2012 5:40:21 AM | Location : United States







Related Discussions:- Converting between the string and number types, Assignment Help, Ask Question on Converting between the string and number types, Get Answer, Expert's Help, Converting between the string and number types Discussions

Write discussion on Converting between the string and number types
Your posts are moderated
Related Questions
printrectarea function: function call: printrectarea(length, width) function header: function printrectarea(len, wid)   In the function call, there are two argume

Intersect function and setdiff function: The intersect function rather than returns all the values which can be found in both of the input argument vectors. >> intersect(v

1. Write a MATLAB function (upperTriangle) using the functions you previously created to convert a matrix to upper triangular form. Start with row 1, column1. Find the row that has

Matrix Multiplication: The Matrix multiplication does not mean multiplying term by term; and it is not an array operation. The Matrix multiplication has a very particular mean

Anonymous Functions: The anonymous function is a very easy, one-line function. The benefit of an anonymous function is that it does not have to be stored in an M-file. This ca

deblank function: The deblank function eliminates only trailing blanks from the string, not leading the blanks. The strtrim function will eliminate both the leading and traili

Illustration of Vectors of structures: In this illustration, the packages are vector which has three elements. It is shown as a column vector. Each and every element is a stru

Removing Whitespace Characters: The MATLAB has functions which will eliminate trailing blanks from the end of a string and/or leading blanks from the starting of a string.

Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>

Storing Strings in Cell Arrays: The one good application of a cell array is to store strings of various lengths. As cell arrays can store various types of values in the elemen