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?
+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
2010-03-03 20:59:01
Both of those worked, but gnovice's was what I was trying to remember. Thanks!
ZalNas
2010-03-04 01:34:47