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".
Test  Status  Code Input and Output 

1  Pass 
A = [ 12 4 7
5 1 4];
B_correct = [ 7 4 12
4 1 5 ];
assert(isequal(swap_ends(A),B_correct))
c =
12
5
d =
7
4
e =
4 7
1 4
e =
4
1
A =
12 4 7
5 1 4
B =
7 4 12
4 1 5

2  Pass 
A = [ 12 7
5 4];
B_correct = [ 7 12
4 5 ];
assert(isequal(swap_ends(A),B_correct))
c =
12
5
d =
7
4
B =
7 12
4 5

3  Pass 
A = [ 1 5 0 2 3 ];
B_correct = [ 3 5 0 2 1 ];
assert(isequal(swap_ends(A),B_correct))
c =
1
d =
3
e =
5 0 2 3
e =
5 0 2
A =
1 5 0 2 3
B =
3 5 0 2 1

4  Pass 
A = 1;
B_correct = 1;
assert(isequal(swap_ends(A),B_correct))

Make one big string out of two smaller strings
1303 Solvers
Back to basics 17  white space
240 Solvers
Create a vector whose elements depend on the previous element
411 Solvers
Given a 4x4 matrix, swap the two middle columns
529 Solvers
1972 Solvers