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
Example of Exponential function modular program: In order to view the distinction in the approximate value for e as n increases, the user kept choosing Limit & entering larger

Plotting from a Function: The following function creates a Figure Window as shown in figure, which shows various types of plots for similar y vector. The vector is passed as a

Examine exponential function: The algorithm for the main script program is shown below:  Call a function eoption to show the menu and return the user's choice.  Loop

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

Modular programs: In a modular program, the answer is broken down into modules, and each is executed as a function. The script is usually known as the main program. In orde

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

Example of file ploting data: As the other example, a data file called 'compsales.dat' stores the sales figures (in millions) for divisions in a company. Each line in the f

Graphics Properties: The MATLAB uses the Handle Graphics in all its figures. All figures consist of various objects, each of which is assigned a handle. The object handle is a

Help command: The help command is used with the script rectarea, the function readlenwid, and the major function printrectarea. To see the first comment in the subfunction, as

Text graphic function - Graphics objects: The text graphic function permits text to be printed in a Figure Window, involving special characters which are printed by using \spe