views:

250

answers:

2

How can I take the first row of a cell array that contains doubles and insert it into a vector, without using a 'for' loop?

+2  A: 

Like this?

avector = cell2mat(acellarray(1,:));
yuk
+4  A: 

You can use curly braces to get entries from the cell array as a comma-separated list, then collect those values into a row vector using square brackets. Here's an example:

>> C = num2cell(magic(5))    %# A sample cell array

C = 

    [17]    [24]    [ 1]    [ 8]    [15]
    [23]    [ 5]    [ 7]    [14]    [16]
    [ 4]    [ 6]    [13]    [20]    [22]
    [10]    [12]    [19]    [21]    [ 3]
    [11]    [18]    [25]    [ 2]    [ 9]

>> vec = [C{1,:}]      %# Put the first row in a vector

vec =

    17    24     1     8    15
gnovice
Both of those worked, but gnovice's was what I was trying to remember. Thanks!
ZalNas