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
Example of Symbolic Expression When there is more than one variable, the MATLAB selects which to solve for. In the illustration below, the equation ax 2 + bx = 0 is solved. Th

Illustration of Standard Deviation The less spread out the numbers are, therefore smaller the standard deviation will be, as it is a way of determining the spread of the data.

Nested IF-ELSE statements: The if-else statement is used to select between the two statements. In order to select from more than two statements, the if-else statements can als

Illustration of Variance For illustration, for the vector [4, 6, 1, 5], there are n = 4 values therefore n - 1 is 3. The mean of this data set is also 4. The variance will be

Indexed empty matrix: The Individual elements cannot be eliminated from matrices, as matrices always have the similar number of elements in every row. >> mat = [7 9 8; 4 6

How do I write a product series running from i to n of x''s using a for loop?

5 p2+8p+15, 3 p2-3p-18, 12 p2-p-30

Structure Consisting of the Fields A MATLAB can also solve the sets of equations. In this illustration, the solutions for x, y, & z are returned as a structure consisting of th

Three-Dimensional Plots: The MATLAB has many functions which will display three-dimensional plots. Most of these functions have similar name as corresponding two-dimensional p

User-defined functions: Therefore, although many functions compute and return values, some do not. A few functions rather merely accomplish a task. Regardless of what type of