The test case is buggy: the beginning of the for loop is on the same line as the %%. Problem is not solvable that way...
Hmm, ok the test works. However, there's no output at all, neither from inside the function nor from the passed/failed test cases. Very annoying...
Every test case should begin with "%%". If it doesn't, then it is treated in Cody as a Shared Variables section (variables available to every test case: intentionally utilized in Problem 44655).
Eventually I have found that this causes problems when the "%%" is unintentionally omitted from test cases, because it causes a very confusing suppression of test case output if an assertion in the nominal SV section fails, but suppresses the nominal Shared Variables section's output if all the SV section is passed without error!! Unfortunately there doesn't appear to be any official public documentation of this, and there's no Cody forum to post about it, but I have left a comment trail at Problems 520, 753 & 970. —DIV
I forgot to mention: if the author of the problem omits "%%" at the start of a Test Suite, Cody displays the Test Suite to the public as if "%%" were inserted before the actual start of the Test Suite. It's a little bit like the way consecutive spaces are hidden in default HTML rendering [or the opposite of that, because Cody is displaying characters that did not exist in the original!].
The "%%" problem here should be fixed now.
Good problem, but, in practice, no one would ever do that. It is better to store the global-linear index and do a quick calculation to find the needed position than to loop through the local indexes. The MATLAB function max has the option 'linear' because of that.
PS: I liked it anyway because it's a good conceptual problem for students to bear down.
An "outstanding" from Alfonso is worth two outstandings.
Similar Triangles - find the height of the tree
Reverse the elements of an array
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
Mersenne Primes vs. All Primes
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office