Cody

Problem 2836. Modify subscripts - easier

Created by Jan Orwat in Community

MATLAB supports object-oriented programming. Let's take an advantage of it in cody.

This problem focus on modifying subscripted references for class double.

This example shows classical behavior:

>> A = [1 4 7
        2 5 8
        3 6 9];
>> A([1 3], [3 1])
ans =
     7     1
     9     3

While this is what I am looking for:

>> modified_A = sub_double(A);
>> modified_A([1 3], [3 1])
ans = 
     7     3
>> modified_A([1 2 2], [3 1 2])
ans = 
     7     2     5

If there are given two subscripts vectors of the same lenght, return only those values which correspond to paired subscriptions.

Task: You are given class template. Complete it to achieve desired behaviour.

Additional info:

  • If you are not familiar with classes in MATLAB you can find more information here and here or you can find it typing:
    >> doc 'Class Definition'
    >> doc 'Customize MATLAB Behavior'
  • Feel free to modify the template,
  • You can try your skills to write a function instead of a class. You can use anonymus functions, etc.,
  • Using classes open another doors to cheat (easily). This is not a hacking problem, so please respect it (you can create some new, interesting problems :-) ),
  • In this form it is solvable without using function "builtin" which is forbidden in cody. I can allow it in the testsuite if there will be need for it,
  • Look for more problems using tags below

Enjoy!

Solution Stats

54.55% Correct | 45.45% Incorrect
Last solution submitted on May 17, 2017

Problem Comments

Recent Solvers5

Suggested Problems

More from this Author47