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
Passing Structures to Functions: The whole structure can be passed to a function, or separate fields can be passed. For illustration, here are the two distinct versions of a f

A matlab function to calculate filter order

function numden: The function numden will return individually the numerator & denominator of a symbolic expression: >> sym(1/3 + 1/2) ans = 5/6 >> [n, d] =

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


analyzing traffic; determine motion of flow; calculate tracklets; detect abnormalities;

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

readlenwid function: function call: [length, width] = readlenwid; function header: function [l,w] = readlenwid In the function call, not any argument is passed; henc

Algorithm for the function e: The algorithm for the function eoption is as shown: Use the menu function to show the 4 choices. Error-check (an error would take place

Example of modular program: In a modular program, there would be one main script which calls three separate functions to complete these tasks: A function to prompt an us