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.
Is the "given dimension" always 2?
Also, provide a few clean test cases. (Here's the input, here's the expected outputs). Or at least let me copy and paste the test case.
* The first [2,6] dimensions of A are non-singleton; A is singleton in all dimensions above first singleton.
* d, the "given dimension", is one of the non-singleton dimensions of A, and the first singleton dimension of I.
* Values in I will be in 1:length(A,d)).
% size(B) should == size(I).
* The problem is that I is the index along the collapsed dimension (d). All other dimensions should use ":".
An "outstanding" from Alfonso is worth two outstandings.
Find the palindrome
Remove the air bubbles
All your base are belong to us
Binary code (array)
Hankelize a matrix
Find the treasures in MATLAB Central and discover how the community can help you!
Select a Web
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