How to initialize an array of structs in MATLAB?

前端 未结 6 467
暗喜
暗喜 2020-11-30 23:01

How can I preallocate an array of structs in MATLAB? I want to preallocate \"a\" in this example so that it does not resize several times.

a = []
for i = 1:1         


        
6条回答
  •  囚心锁ツ
    2020-11-30 23:44

    There's a nice discussion about this in Loren on the Art of MATLAB blog.

    If I understand you correctly, here's a ways to initialize the struct you want:

    a(100).x = 100;
    

    With this method, we can see that elements are filled in with empty arrays.

提交回复
热议问题