将结构转换为数组

时间:2012-02-18 01:34:45

标签: matlab

这是a的简化版本 考虑Matlab中的数据结构:

 struct(1).left=1;struct(2).left=2;struct(3).left=3;

现在我想把它复制成一个整数数组

K>> arrayL(1:3)=struct.left

arrayL =

 1     1     1

为什么它只将struct.left的第一个元素处理成arrayL?如何将整个结构(1:3)复制到arrayL中,使其包含1,2,3? 感谢

2 个答案:

答案 0 :(得分:5)

我目前没有matlab方便,但请尝试arrayL = [struct.left];(因为struct.left本身会返回3个单独的答案,每个元素对struct中的每个元素都有一个答案。)

答案 1 :(得分:0)

您可以尝试使用cell2mat函数http://www.mathworks.com/help/matlab/ref/cell2mat.html

相关问题