This solution is outdated. To rescore this solution, sign in.
-
3 Comments
Why does it not work? Why does it return wrong vector 'ind' ?
That's two different questions. (1) It doesn't work because "find" returns a column vector. This can be fixed by transposing the "ind" in the "for" statement, as I've done in Solution 1276663 to this problem. (2) AFAIK, there is an unknown glitch in Cody whereby the preceding bug in your code caused the contents of "ind" to be misreported; actually the contents of your "ind" were fine, as Solution 1276663 shows.
Thanks David. Previously I did get a solution with a transposed "ind" working (see Solution 1142933). It seems at that time I just wasn't aware yet that a for-loop assigns not just scalars but whole column vectors to its index variable ('j").
However, this still leaves me puzzled about why the wrong value of "ind" is reported (*before* entering the for-loop); but this is probably indeed just a glitch in Cody or this test suite.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!