Problem 2836. Modify subscripts - easier

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

65.22% Correct | 34.78% Incorrect
Last Solution submitted on Aug 15, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers13

Suggested Problems

More from this Author40

Community Treasure Hunt

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

Start Hunting!