Strings as matrix, MATLAB in Mathematics

Strings as matrix:

The matrix can be generated, that consists of strings in each row. Therefore, essentially it is created as a column vector of strings, but the final result is that this would be considered as a matrix in which each and every element is a character:

>> wordmat = ['Hello';'Howdy']

wordmat =

Hello

Howdy

>> size(wordmat)

ans =

2    5

This generated a 2 × 5 matrix of characters.

With the character matrix, we can refer to an individual element, that is a character, or a separated row, that is one of the strings:

>> wordmat(2,4)

ans =

d

>> wordmat(1,:)

ans =

Hello

As rows within a matrix should always be of similar length, the shorter strings should be padded with blanks so that all the strings have similar length, or else an error will occur.

>> greetmat = ['Hello'; 'Goodbye']

??? Error using ==> vertcat

The dimensions of CAT arguments are not consistent.

>> greetmat = ['Hello  '; 'Goodbye']

greetmat =

Hello

Goodbye

>> size(greetmat)

ans =

2    7

Posted Date: 10/20/2012 4:30:37 AM | Location : United States







Related Discussions:- Strings as matrix, Assignment Help, Ask Question on Strings as matrix, Get Answer, Expert's Help, Strings as matrix Discussions

Write discussion on Strings as matrix
Your posts are moderated
Related Questions
If I have a vector representing the packed storage form of a symmetric matrix, how do I perform a cholesky factorisation on that?

Give the formula for a rational function that has a hole at x=7 & vertical asmptote at x=-3/2

Pie chart - plot functions: The MATLAB also has a function pie which will generate a pie chart. Calling the function with the form pie (vec) draws a pie chart, by using the pe

Illustration of Spreadsheet Files: This reads the numbers in a double vector variable nums and the text in a cell array txt (the xlsread function forever returns the numbers f

Concatenation: The String concatenation means to join the strings altogether. Of course, as strings are merely vectors of the characters, the technique of concatenating vector

Strcat function - Concatenation : The strcat function, though, will eliminate the trailing blanks from strings before concatenating. Note that in these illustrations, the trail

Creating Customized strings: There are many built-in functions which create customized strings, including blanks, char, and sprintf. We know that the char function can be u

Built-in functions for Complex numbers:   We know that in MATLAB both i and j are built-in functions which return √-1 (therefore, they can be thought of as built-in constants).

Three-dimensional pie and bar: For the bar3 function, x & y vectors are passed and the function displays three-dimensional bars as shown in figure: Figure: Three-dimen

Logical Vectors: The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each eleme