Cody

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

Solution 1679997

Submitted on 24 Nov 2018 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
s1 = struct('foo',1,'bar',2,'baz',3); s2 = struct('foo',3,'bar',2,'baz',1); f_correct = {'foo';'baz'}; v_correct = {3;1}; [f,v] = modfields(s1,s2); assert(isequal(f,f_correct)) assert(isequal(v,v_correct))

2   Pass
s1 = struct('foo1','the','foo2','purpose','foo3','of','foo4','this','foo5','example','foo6','is','foo7','to test strings!'); s2 = struct('foo1','did','foo2','you','foo3','get','foo4','the answer','foo5','example','foo6','correct?','foo7','to test strings!'); f_correct = {'foo1';'foo2';'foo3';'foo4';'foo6'}; v_correct = {'did';'you';'get';'the answer';'correct?'}; [f,v] = modfields(s1,s2); assert(isequal(f,f_correct)) assert(isequal(v,v_correct))

3   Pass
s1 = struct('num',1:1000,'str','This is just a test!'); s1.cll = {1:1000,'This is just a test!'}; s2 = s1; f_correct = []; v_correct = []; [f,v] = modfields(s1,s2); assert(isequal(f,f_correct)) assert(isequal(v,v_correct))

4   Pass
s1 = struct('num',magic(3),'str','magic'); s1.cll = {magic(4),magic(5),magic(6)}; s2 = s1; s2.cll = {magic(6),magic(5),magic(4)}; f_correct = {'cll'}; v_correct = {{magic(6),magic(5),magic(4)}}; [f,v] = modfields(s1,s2); assert(isequal(f,f_correct)) assert(isequal(v,v_correct))

Community Treasure Hunt

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

Start Hunting!