Combine two structure variables with different fields

Combine two structure variables with different fields x.a, x.b y.c,y.d z=combinefield(x,y) z.a,z.b,z.c,z.d

You are now following this Submission

function [Out]=combineField(A,B)
% Combine two structure variables into one
% A and B are stuructures want to include both
% Out: Output.

fnames=fieldnames(B);
for is=1:length(fnames)
Data=getfield(B,fnames{is});
A=setfield(A,fnames{is},Data);
end
Out=A;

Cite As

Taesam Lee (2026). Combine two structure variables with different fields (https://au.mathworks.com/matlabcentral/fileexchange/71213-combine-two-structure-variables-with-different-fields), MATLAB Central File Exchange. Retrieved .

Tags

Add Tags

Add the first tag.

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0