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
str2num function - String: The function str2num does the opposite; it takes the string in which a number is stored and converts it to the type double: >> num = str2num('123.

I have a frequency response data. How do I convert that to state space? I am given a 6 row and 3 column data (steady state). How do i convert that to state space model?

Illustration of Variable scope: Running this function does not add any of variables to the workspace, as elaborated: >> clear >> who >> disp(mysum([5 9 1]))

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

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

Q.1: Consider the transmission of a sinusoid x(t) = cos(2f0t) through a channel a ected by multipath and Doppler. Let there be two paths, and assume the sinusoid is being sent fro

Plotting File data: It is frequently essential to read data from a file and plot it. Generally, this entails knowing the format of the file. For illustration, let us suppose t

Illustration of anonymous functions: Dissimilar functions stored in the M-files, when no argument is passed to an anonymous function, the parentheses should still be in the fu

Illustration of symbolic variable: When, on the other hand, z is a symbolic variable to start with, quotes are not required around the expression, and the words are automatica

Binary Search: The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone direc