File Exchange Pick of the Week

June 23rd, 2008

MATLAB Basics: Cell arrays for holding different data types

Sometimes in MATLAB you are going to want to store different data types together in one construct rather than try and keep track of different variables. Structures work for this, but sometimes it is nice to be able to refer to the data in row and column notation rather than by field name. That is where cell arrays work best.

This video will show the construction of a cell array that contains four scalars and then a string is added. Finally, a cell array is put inside of the original cell array. This is possible, because cell arrays can hold any data type.


Video Content

iconFiles.jpgiconPod.jpg

5 Responses to “MATLAB Basics: Cell arrays for holding different data types”

  1. Ritwik Banerjee replied on :

    Thanks a bunch for this easy-to-understand video. This short post taught me a lot!! I was going to so many forums to learn this thing, but this is where I finally understood it clearly. Thanks again. :)

  2. MAuricio replied on :

    Well. thanks for the attention
    I want to know how to see the data saved on a cell, look at this:
    features{1,13,2}
    ans =

    [1x16 double]
    features(1,13,1)

    ans =

    {1×1 cell}

    Well the matter is i want to view the values of the data saved, but i don“t know how

  3. Steve L replied on :

    MAuricio,

    From the description it sounds like the features variable is a cell array that itself contains a cell array.

    innercell = {1, 2, 3};
    outercell = {'abc', innercell}
    

    To do this, you will need to “drill into” the cell array multiple levels to see the contents of the innermost cell array.

    innercell2 = outercell{1, 2}
    innerdata = outercell{1, 2}{1}
    

    Depending on how deeply nested the cell arrays are, you may need to use several layers of indexing to obtain the actual raw data.

  4. Liqing replied on :

    Thank you for the nice short video. It is very helpful.

  5. Amanda replied on :

    Thanks so much for this tutorial! Very clear and easy to understand.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.