I noticed various cases in Matlab and the octave, where functions accept both matrices and vectors, but do not do the same with vectors as they do with matrices.
This can be frustrating because when you enter a matrix with a variable number of rows / columns, it can be interpreted as a vector and do what you do not expect when height / width 1 makes conditional edge cases difficult for debugging and strange.
I will list the list that I found, but I'm curious that other people have come across
(Note: I'm only looking for cases where the code takes matrices as valid input. Anything that throws an exception when a non-vector matrix is given as an argument is not taken into account)
1) "diag" can be used to denote the diagonal of a matrix or to convert a vector into a diagonal matrix
Since the first one is usually used only for square matrices, it is not so blatant in matlab, but in Octave it can be especially painful when Octave alternates a vector starting with a nonzero element and all other zeros as a “diagonal matrix”, then there is
t=eye(3);
size(diag(t(:,3))) == [3,3]
size(diag(t(:,2))) == [3,3]
size(diag(t(:,1))) == [1,1]
2) Indexing into a row vector with logical elements returns a row vector
Indexing to anything else using gates returns a column vector
a = 1:3;
b = true(1,3);
size(a(b)) == [1, 3]
a = [a; a];
b = [b; b];
size(a(b)) == [6, 1]
3) Indexing into vector v with index I returns a vector of the same type (row / col) as v. But if v or i is a matrix, the return value is the same size as i.
a = 1:3;
b = a';
size(a(b)) == [1, 3]
b = [b,b];
size(a(b)) == [3, 2]
4) max, min, sum .. M , M 1xn, M -
a = 1:3
size(max(a)) == [1, 1]
a = [a;a]
size(max(a)) == [1, 3]
max , ( )
/matlab?