matlab向结构体中的数组自动赋值_如何在MATLAB中初始化结构体数组?

阅读: 评论:0

matlab向结构体中的数组⾃动赋值_如何在MATLAB中初始化
结构体数组?氯喹那多
使⽤repmat是⽬前为⽌预分配结构体的最有效的⽅法:
N = 10000;
b = repmat(struct('x',1), N, 1 );
这是使⽤Matlab 2011a⽐预分配通过索引,〜10倍更快
N = 10000;
b(N).x = 1
索引⽅法仅略微快于不预分配。
No preallocation: 0.075524
Preallocate Using indexing: 0.063774
Preallocate with repmat: 0.005234
下⾯的代码,以防想要验证。
clear;
N = 10000;
%1) GROWING A STRUCT
tic;
for ii=1:N
a(ii).x(1)=1;
george booleend
noPreAll = toc;
pro e%2)PREALLOCATING A STRUCT
tic;
让子弹飞 久石让b = repmat( struct( 'x', 1 ), N, 1 );
for ii=1:N
气缸耗气量计算
b(ii).x(1)=1;
end;
澳门八国联军表演
repmatBased=toc;
%3)Index to preallocate
c(N).x = 1;
for ii=1:N
c(ii).x(1)=1;
end;
preIndex=toc;
disp(['No preallocation: ' num2str(noPreAll)])
disp(['Preallocate Indexing: ' num2str(preIndex)])
disp(['Preallocate with repmat: ' num2str(repmatBased)]) No preallocation: 0.075524
Preallocate Indexing: 0.063774
Preallocate with repmat: 0.0052338
>>
P.S。我有兴趣知道为什么这是真的,如果有⼈可以解释它。

本文发布于:2023-08-15 05:50:41,感谢您对本站的认可!

本文链接:https://patent.en369.cn/xueshu/361214.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:结构   数组   想要   以防   计算
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图