Showing cell array elements and attributes, MATLAB in Engineering

Referring to and Showing Cell Array Elements and Attributes:

Just as with the other vectors, we can refer to individual elements of the cell arrays. The only difference is that the curly braces are used for the subscripts. For illustration, this refers to the second element of the cell array cellrowvec:

> cellrowvec{2}

ans =

a

 

The Row and column indices are used to refer to an element in a matrix for illustration,

>> cellmat{1,1}

ans =

23

 

The Values can be assigned to cell array elements. For illustration, after preallocating the variable mycellmat, the elements can be initialized:

>> mycellmat{1,1} = 23

mycellmat =

[23]  []

[]  []

 

Whenever an element of a cell array is itself a data structure, then only the type of the element is displayed when the cell array contents are shown. For illustration, in the cell arrays just generated, the vector is shown just as 1 × 5 double. Referring to that element particularly would display its contents, the illustration is as follows,

>> cellmat{2,1}

ans =

  1   3   5   7   9

 

As this element is a vector, the parentheses are used to refer to its elements. For illustration, the fourth element of the preceding vector is as shown below:

>> cellmat{2,1}(4)

ans =

  7

Note that the index in the cell array is given in the curly braces, and then parentheses are used to refer to an element of the vector.

We can also refer the subsets of cell arrays, for illustration,

>> cellcolvec{2:3}

ans =

a

ans =

  1   3   5   7   9

 

Note, though, that MATLAB stored cellcolvec{2} in the default variable ans, and then substituted that with the value of cellcolvec{3}. This is because the two values are of various types, and hence cannot be stored altogether in ans.

Though, they could be stored in two separate variables by having a vector of variables on the left-hand side of the assignment.

>> [c1 c2] = cellcolvec{2:3}

c1 =

a

c2 =

  1   3   5   7   9

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







Related Discussions:- Showing cell array elements and attributes, Assignment Help, Ask Question on Showing cell array elements and attributes, Get Answer, Expert's Help, Showing cell array elements and attributes Discussions

Write discussion on Showing cell array elements and attributes
Your posts are moderated
Related Questions
Inverse of square matrix: The inverse is, hence the result of multiplying the scalar 1/D by each and every element in the preceding matrix. Note that this is not the matrix A,

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

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

Illustration of Set operations: For illustration, given the vectors as shown below: >> v1 = 2:6 v1 = 2  3  4  5  6 >> v2 = 1:2:7 v2 = 1  3  5  7

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente

num2str function: The num2str function, that converts real numbers, can be called in many ways. If only the real number is passed to the num2str function, it will generate a s

Illustration of gauss-jordan: Here's an illustration of performing such substitutions by using MATLAB >> a = [1 3 0; 2 1 3; 4 2 3] a = 1 3 0 2 1 3 4 2

Illustration of if - else statement: The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted t

Individual structure variable: The individual structure variable for one software package may look like this: The name of the structure variable is a package; it has f

Function used in binary search: The function below implements this binary search algorithm. It receives two arguments: the sorted vector and a key (on the other hand, the func