How to initialize an array of structs in MATLAB?

前端 未结 6 465
暗喜
暗喜 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:19

    According to this answer, there's also another way to do it:

    [a.x] = deal(val);
    

    where val is the value you want to assign to every element of the struct.

    The effect of this command is different from those of the others, as every x field of every structure a will be assigned the val value.

提交回复
热议问题