matlab结构体怎么变为数组

仍觉不够 1个月前 已收到1个回答 举报

當作善良 2星

共回答了81个问题采纳率:93.3% 评论

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

17小时前

4
可能相似的问题

猜你喜欢的问题

热门问题推荐

Copyright © 2024 微短问答 All rights reserved. 粤ICP备2021119249号 站务邮箱 959505@qq.com