全站数据
8 4 2 0 5 8 1

matlab结构体怎么变为数组

外盘期货 | 简单学习,快乐成才!         
问题更新日期:2024-11-04 05:04:06

问题描述

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