I understand this is a classic question and some aspects of it have been answered before, for instance here: How can I index a MATLAB array returned by a function without first assigning it to a local variable?
But reading through the comments it has become clear that i) some of the proposed solutions don't work anymore (the ones based on builtin or feval) or ii) don't work for certain classes or indices.
Specifically for a cell array A, the results of A{:} and subsref(A,substruct('{}',{':'})) are not the same.
For the sake of completeness, I'd like to point out that cell2mat(A) is not the same as A{:} and does not help either.
To clarify further why this is relevant, if A was just a variable there would be no need for subsref. However, if A is a more general expression such as B{1} or C(1) etc, Matlab does not let you further index it with {:}.
A minimal working example showing the problem:
A=arrayfun(@(x) rand(2,2,2),ones(3,1),'Uni',0)
cat(4,A{:})
compared to:
cat(4,subsref(arrayfun(@(x) rand(2,2,2),ones(3,1),'Uni',0),substruct('{}',{':'})))
which only works on the first element.
I tested in R2019b and
subsref(A,substruct('{}',{':'}))seems to return the same asA{:}, namely, a comma-separated list of the contents of the cell array. However, sincesubsrefis a function, you need to specify how many outputs you want; by default it only provides the first one. Compare: