I doubt that there is a real vectorized way. If you really need this small low speed, do not use structures.
Here is the loop solution:
fn = fieldnames(S2) for ii = 1:numel(fn), S1.(fn{ii}) = S2.(fn{ii}); end
The reason why there is no trivial solution is because Matlab cannot know in advance that there is no field c or d in S1 , and if so, then a conflict will arise.
Jolo's answer seems to be vectorized, although I don't know how these functions work internally. And they are probably not much faster than a simple loop.
source share