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?
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
Like this?
avector = cell2mat(acellarray(1,:));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With