Create a function handle that reverses the input arguments of another function handle - MATLAB Cody - MATLAB Central

Problem 260. Create a function handle that reverses the input arguments of another function handle

Difficulty:Rate

Given a function that takes two input arguments and returns one output, create another function handle that performs the same operation but with the input arguments in reverse order.

For example:

   f = @(x,y) 2*x+y;
   f(5,6)

returns the answer 16. Your function should produce another function handle that performs the same operation except that y is the first input argument and x is the second.

   g = reverseArguments(f);
   g(6,5)

returns 16, and:

   g(5,6)

returns 17.

Solution Stats

60.41% Correct | 39.59% Incorrect
Last Solution submitted on Apr 04, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers152

Suggested Problems

More from this Author5

Community Treasure Hunt

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

Start Hunting!