Matlab: 结构体数组的某字段 转为 数组
(2011-11-01 21:40:09)
标签:
struct2cellcell2mat教育 |
分类: Matlab |
use the function
* struct2cell()
* cell2mat()
------------------- Test Code -------------------------
function demo_structArray()
% create a
struct array
NUM =
10;
a =
struct('name',cell(NUM,1),'val',1); % a 10-by-1 struct array with 2
field
% we want to
get the a(:).val as an array
a_cell =
struct2cell(a); % a_cell is a 2-by-10 cell array
b =
a_cell(2,:);
b =
cell2mat(b);
b
end
----------------- Results ---------------
b =
1
1
1
1
1
1
1
1
1
1
-------------------------------------------------------------
* struct2cell()
* cell2mat()
------------------- Test Code -------------------------
function demo_structArray()
end
----------------- Results ---------------
b =
-------------------------------------------------------------

加载中…