This problem was fun. I was able to find a better way to solve beat my own solution. Not the best way though. But lot better.
@Alireza yarmohammadi: your comment was deleted as it revealed an answer to the problem.
In response to the question you asked, though, your function returns m, which is not the complete answer. The last line in your function displays the correct result, but assigns it to ans, not m.
314 Solvers
553 Solvers
358 Solvers
469 Solvers
276 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!