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
how can reconstruct just part of an image using imreconstruct?

This project requires you to use the ideas of Chapter 25 regarding maximization of a function. Here we assume that evolution has acted to generate highly efficient foragers. By hig

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,

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

Animation: In this part we will observe a couple of ways to animate a plot. These are visuals, therefore the outcomes can't really be shown here; it is essential to type these

Illustration of Logical vectors: Calling the function appears to return similar vector as simply vec > 5, and summing the result still works to determine how many elements wer

Empty Vectors: An empty vector or in another words, a vector which stores no values, can be generated using the empty square brackets: >> evec = [] evec = [] >> lengt

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

Writing variables to a File: The save command is used to write variables to a file, or to append the variables to a MAT-file. By the default, save function writes to a MAT-fil

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