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
Problem Comments
-
4 Comments
Are they still allowing classes? My solution passed all the tests on my computer.
However, when I ran it on Cody, I got "Something went wrong. Please check your code for errors and try again later."
Hi Andrew, I will check it out.
Whatever the problem is, it went away.
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
Find the two most distant points
2845 Solvers
-
English to Pig Latin Translator
148 Solvers
-
311 Solvers
-
249 Solvers
-
194 Solvers
More from this Author40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!