Combine two structure variables with different fields

Version 1.0.0 (1.14 KB) by Taesam Lee
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
17 Downloads
Updated 15 Apr 2019

View License

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 (2024). Combine two structure variables with different fields (https://www.mathworks.com/matlabcentral/fileexchange/71213-combine-two-structure-variables-with-different-fields), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0