defining arrays of structure

2 次查看(过去 30 天)
AP
AP 2011-6-1
In order to increase the speed of processing, I am trying to define an array of structures before proceeding to my main code, say, 100×50 arrays of the same structure. How can I define it beforehand?
struct('dir1',{},'dir2',{},'x1',{},'x2',{},'x3',{},'x4',{})
is the following correct?
n1=100;
n2=50;
data{n1,n2}=struct('dir1',{},'dir2',{},'x1',{},'x2',{},'x3',{},'x4',{})
Thanks a lot for your quick reply :)

采纳的回答

Jan
Jan 2011-6-1
C = cell(100, 50);
S = struct('dir1', C, 'dir2', C ,'x1', C, 'x2', C, 'x3', C, 'x4', C);
Another method:
% S must be undefined before, otherwise use "clear('S')"
S(100, 50) = struct('dir1', [], 'dir2', [] ,'x1', [], ...
'x2', [], 'x3', [], 'x4', []);
  7 个评论
Jan
Jan 2011-6-1
@Ahmad: The S(100, 50)=struct() is 3 times faster. But we are talking about 0.1e-3 sec. I assume that reading this message will waste more time than using the worse method.
AP
AP 2011-6-1
Jan you're a real MATLABer :)
Thank you for your helps.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by