Cody

# Problem 43686. Apply Function to Each Field of a Structure Array: Part 2

Solution 2126029

Submitted on 12 Feb 2020 by Stefano Gianoli
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
s.f1 = 'Sunday'; s.f2 = 'Monday'; s.f3 = 'Tuesday'; s.f4 = 'Wednesday'; s.f5 = 'Thursday'; s.f6 = 'Friday'; s.f7 = 'Saturday'; f = @(x)x(1:3); c = structfun(f,s,'UniformOutput',false); assert(isequal(structfun2(f,s),c))

2   Pass
s = struct('f1',{1, [3 4;5 6]; 1, [5 6;7 8]},'f2',{[1 2], 2; [3 4 5;6 7 8], [2 6;4 5]}); f = @min; c = struct('f1',{1, [3 4]; 1, [5 6]},'f2',{1, 2; [3 4 5], [2 5]}); assert(isequal(structfun2(f,s),c))

3   Pass
s = struct('f1',{1, [3 4;5 6]; 1, [5 6;7 8]},'f2',{[1 2], 2; [3 4 5;6 7 8], [2 6;4 5]}); f = @sum; c = struct('f1',{1, [8 10]; 1, [12 14]},'f2',{3, 2; [9 11 13], [6 11]}); assert(isequal(structfun2(f,s),c))

4   Pass
s = struct('f1',{1, [3 4;5 6]; 1, [5 6;7 8]},'f2',{[1 2], 2; [3 4 5;6 7 8], [2 6;4 5]}); f = @pow2; c = struct('f1',{2, [8 16;32 64]; 2, [32 64;128 256]},'f2',{[2 4], 4; [8 16 32;64 128 256], [4 64;16 32]}); assert(isequal(structfun2(f,s),c))

### Community Treasure Hunt

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

Start Hunting!