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
Script a MATLAB program which meets the following speci cations: The program expects an input of a two-variable real-valued continuous function f : R^2--> R The program is to cal

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 Labels and prompts: The program below prompts the user for endpoints (x1, y1) and (x2, y2) of a line segment, and computes the midpoint of the line segment, th

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

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

Function fopen - file function: The permission string in the call to the fopen function identifies that the file is opened for writing to it. Just as when reading from a file,

Function isreal - complex numbers: The function isreal returns 1 for logical true when there is no imaginary part of the argument, or 0 for false when the argument does have a

Referring to and Modifying the Matrix Elements: To refer to matrix elements, the row and then the column indices are given in parentheses (always the row index initially and t

Find Minimum and Maximum for each row To find the maximum (or minimum) for each row, the dimension of 2 (that is how a MATLAB refers to rows) can be identified as the third arg

Applications of Customized Strings: Labels, Prompts, Arguments to Functions: The one of very useful application of this is to involve numbers in strings that are used to plot