Cody

Problem 2641. Dispatch and collect

Solution 552564

Submitted on 6 Jan 2015 by Alfonso Nieto-Castanon
• Size: 37
• This is the leading solution.
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
%% 2 outputs, 2 functions x = [1 2 6; 2 7 5; 3 5 4]; co1 = [1 2 4; 3 7 6]; co2 = [1 1 3; 3 2 1]; [o1, o2] = dispatch(x, @min, @max); assert(isequal(o1, co1) && isequal(o2, co2))

2   Pass
%% 1 output, 3 functions x = randi(50, 20); co = [mean(x); mode(x); median(x)]; assert(isequal(co, dispatch(x, @mean, @mode, @median)))

3   Pass
%% 1 output, 5 functions x=10; co = [zeros(x);ones(x);eye(x);magic(x);pascal(x)]; assert(isequal(co, dispatch(x, @zeros, @ones, @eye, @magic, @pascal)))

4   Pass
%% 4 outputs, 1 function co = randi(50, 1, 4); [o1, o2, o3, o4] = dispatch(zeros(co), @size); assert(isequal([o1 o2 o3 o4], co))

Community Treasure Hunt

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

Start Hunting!