Doug's MATLAB Video Tutorials

January 13th, 2011

How to add to a cell array in MATLAB

This MATLAB user needed to add another row to a cell array so they could populate the data in a uitable. Uitable requires that all the cells in a given column are of the same type. This video shows how to cast the values of a cell array so that this constraint is met.

2 Responses to “How to add to a cell array in MATLAB”

  1. Louis replied on :

    I have determined a programmatic way to do the same. I welcome comments on this approach.

    load('data.mat')
    newRow = cellfun(@(x)(cast([],class(x))),data(1,:),'UniformOutput',false)
    data = cat(1,data,newRow)
    

    ~Louis

  2. dhull replied on :

    @Louis,

    There are many ways to do things in MATLAB and other languages. I tend to prefer code that is easiest to read as my first metric. It is good to know of more robust, if not more cryptic, techniques. There are places where your solution would be much better.

    Thanks for adding it.

    Doug

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

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

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