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
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

Replacing, Finding, and separating strings: There are numerous functions which find and replace the strings, or parts of strings, within the other strings and functions which

Changing Case: The MATLAB has two functions which convert strings to all uppercase letters, or all lowercase, known as the upper and lower. >> mystring = 'AbCDEfgh';

Set Operations: The MATLAB has numerous built-in functions which perform set operations on vectors. These involve intersect, union, setdiff, unique, and setxor. All these func

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

Function used in sound files: The MATLAB has numerous other functions which let you read and play sound or audio files. In the audio files, sampled data for each audio channel

Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

i want to run 4 instances of my matlab code on 4 processor cores. im executing the job from head node. i created a parallel job and assigned number of workers. but i don''t get bac

Finding products by for loop: an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15: >> s

FOR Loop: The for loop, or the for statement, is used whenever it is essential to repeat statement(s) in the script or function, and whenever it is known ahead of time how man