If we consider a function that is meant to operate on the first non-singleton dimension of a matrix, is there a direct way to find the size and index of this non-singleton dimension? For instance, if the user inputs a matrix of size 1, N, M, is there a function that could output that the first non-singleton dimension is 2 with size N?
In other words, is there a function that would return directly the first non-singleton dimension fnsd and first non-singleton size fnss as in the code below?
% create matrix with two singleton dims first
x = rand(1, 1, 10, 20);
% find the first non-singleton dimension
fnsd = find(size(x) > 1, 1);
% get the first non-singleton size
fuss = size(x, fnsd);