Insert doubles in an array of cells in a vector in MATLAB

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

+4
source share
2 answers

You can use curly braces to get entries from an array of cells as a comma-separated list , then collect these values ​​in a row vector using square brackets. Here is 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 
+6
source

Like this?

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

Source: https://habr.com/ru/post/1303044/


All Articles