Getting a sum of the cell??? - MATLAB

Discussion in 'Programmer's Corner' started by Judas543, Apr 7, 2010.

  1. Judas543

    Thread Starter Member

    Jan 26, 2010
    60
    0
    sstart this file in matlab

    http://www.sendspace.com/file/qudqdk

    1) This file contains only one variable: a cell array y. I'm suppose to add all the elements in y and give the sum.


    How do i do that if its in the cell?


    If i do like sum(y) or something i get an error
     
  2. Ghar

    Active Member

    Mar 8, 2010
    655
    72
    I don't have Matlab here but try y{:} instead of just y.
    The problem with cell arrays is that y(x) returns the cell (so the array [5] for example) while y{x} returns the cell contents (just 5).
     
  3. Judas543

    Thread Starter Member

    Jan 26, 2010
    60
    0
    ah i see. Thanks i got it!
     
Loading...