在MATLAB中将单元格数组中的双精度数插入到矢量中

时间:2010-03-03 20:31:33

标签: arrays matlab vector cell

如何在不使用'for'循环的情况下,将包含双精度数的单元格数组的第一行插入向量中?

2 个答案:

答案 0 :(得分:6)

您可以使用大括号get entries from the cell array作为comma-separated list,然后使用方括号将这些值收集到行向量中。这是一个例子:

>> 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

答案 1 :(得分:4)

喜欢这个吗?

avector = cell2mat(acellarray(1,:));