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 =



>> 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 =


>> wordmat(1,:)

ans =


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 =



>> 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
Use of logical vector: Determine how many elements in the vector vec were greater than 5, the sum function can be used on the resulting vector isg: >> sum(isg) ans =

Writing and Reading Spreadsheet Files: The MATLAB functions xlswrite & xlsread will write to and read from the spreadsheet files which have the extension .xls. For illustratio

Use of string variables: The Characters involve letters of the alphabet, punctuation marks, digits, white space, and control characters. The Control characters are characters

Creating string Variables: The string consists of a few numbers of characters (including, possibly, none). These are the illustrations of the strings: '' 'x' 'ca

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

Print an imaginary number: To print an imaginary number, the function disp will show both parts automatically: >> disp(z1)    4.0000 + 2.0000i The function fprint

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

Illustration of Advanced file input and output: For illustration, to refer to the third number in the first element of the cell array: >> subjdata{1}(3) ans =

Labels and Prompts: The script loads all the numbers from file into a row vector. It then splits the vector; it stores the initial element that is the experiment number in a v

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