Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 1689. Determine which fields have been modified in a structure

Created by Matt Eicholtz

Given two input structures (s1, s2), determine which field values have been modified in s2 compared to s1. Your output should be a cell array of appropriate fieldnames and a cell array of the corresponding s2 field values. If s1 and s2 are identical (i.e. no values have been changed), return [] for both outputs.


Suppose = 1; = 2;
s1.baz = 3;

and = 1; = 0;
s2.baz = 3;

then the correct output is

f = {'bar'}
v = {0}


  • Inputs are scalar structures
  • Inputs have identical fieldnames
  • Field values can be numeric arrays, strings, or cell arrays
  • The ith cell in output f corresponds to the ith cell in output v

Problem Group

Solution Statistics

13 correct solutions 10 incorrect solutions
Last solution submitted on Nov 13, 2014