This solution is outdated. To rescore this solution, sign in.
-
1 Comment
A couple of comments:
(1) The first case of setting B=1 when there is only one column in A will satisfy the test case on Cody, for which A=[1], but is not a general solution. For example, it would not generate the correct output if A=[7], nor if A=[1; 1].
(2) You have six separate, but identical, evaluations of size(A,2)). It would seem to make sense to evaluate this once only, and to assign it to a variable.
(3) Although your structure of three separate "if" statements clearly works, you could consider using instead "elseif" and "else" within a single "if" statement. Alternatively you could also use "switch, case, otherwise".
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!