Storing strings in cell arrays, MATLAB in Engineering

Storing Strings in Cell Arrays:

The one good application of a cell array is to store strings of various lengths. As cell arrays can store various types of values in the elements, that means that the strings of various lengths can be stored in the elements.

>> names = {'Sue', 'Cathy', 'Xavier'}

names =

  'Sue'   'Cathy'   'Xavier'

 

This is very useful, as unlike vectors of strings generated using char or strvcat, such strings do not have extra trailing blanks.

The length of each string can be exhibited using a for loop to loop through the elements of the cell array:

 

>> for i = 1:length(names)

disp(length(names{i}))

  end

3

5

6

 

It is possible to convert a cell array of strings to a character array, and vice versa. The MATLAB has numerous functions which facilitate this. For illustration, the function cellstr converts from a character array padded with blanks to the cell array in which the trailing blanks have been eliminated.

>> greetmat = char('Hello','Goodbye');

>> cellgreets = cellstr(greetmat)

cellgreets =

'Hello'

'Goodbye'

 

The char function can convert a cell array to the character matrix:

>> names = {'Sue', 'Cathy', 'Xavier'};

>> cnames = char(names)

cnames =

Sue

Cathy

Xavier

>> size(cnames)

ans =

  3    6

Posted Date: 10/20/2012 5:50:25 AM | Location : United States







Related Discussions:- Storing strings in cell arrays, Assignment Help, Ask Question on Storing strings in cell arrays, Get Answer, Expert's Help, Storing strings in cell arrays Discussions

Write discussion on Storing strings in cell arrays
Your posts are moderated
Related Questions
Example of Exponential function modular program: In order to view the distinction in the approximate value for e as n increases, the user kept choosing Limit & entering larger

I have a vector of X, one for Y , one for x-direction velocity U and one for y-direction velocity V. they are at same size. How can I plot streamline of that flow? I follow all exa

Data structures: The Data structures are variables which store more than one value. In order to made sense to store more than one value in a variable, the values must in some

Illustration of initializing the data structure: illustration of initializing the data structure by preallocating is here as shown: >> cyls(3) = struct('code', 'c', 'dimen

Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t

Examine exponential function: The algorithm for the main script program is shown below:  Call a function eoption to show the menu and return the user's choice.  Loop

. Generate the following signal, x(n)=1+cos((25*pi*n)/100),0 Compute the DTFT of x[n] for w=0:0.01:2*pi Plot the Real part, imaginary part, the amplitude and phas

Function used in sound files: The MATLAB has numerous other functions which let you read and play sound or audio files. In the audio files, sampled data for each audio channel

Graphics Properties: The MATLAB uses the Handle Graphics in all its figures. All figures consist of various objects, each of which is assigned a handle. The object handle is a