How to set missing fields in a structure array to default values stored in another structure array (with same field names)?
显示 更早的评论
Hi Everyone,
I am wondering if there is a way to set 'missing' fields in a structure to 'default' values stored in a default structure. For example, say I have the structures 's' and 'd' below, and want to set any fields that 'd' contains that to not exist in 's' to the values in 'd'.
s.fa = 1;
s.fb = 'b';
d.fa = 1;
d.fb = 'a';
d.fc = "a";
I would like to create the field s.fc = d.fc, without changing the value of s.fb to d.fb.
For some background, I am developing a Matlab application in App Developer, and I am storing 'designs' as structures and structure arrays in .mat files. I am frequently expanding capabilities and fields, and would like to maintain backwards compatibility for previous designs (which have less fields), by setting missing fields to default values stored in a default structure. The actual design will contain nested structures (structure levels?), as well as structure arrays that are not necessarily the same size.
Thanks!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Variables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!