Q:

How to return the leaves of a struct as vector in Matlab? 

Often I need to access the leaves of data in a structured array for calculations. 
How is this best done in Matlab 2017b? 
% Minimal working example:
egg(1).weight = 30;
egg(2).weight = 33;
egg(3).weight = 34;

someeggs = mean([egg.weight]) % works fine

apple(1).properties.weight = 300;
apple(2).properties.weight = 330;
apple(3).properties.weight = 340;

someapples = mean([apple.properties.weight]) %fails
weights = [apple.properties.weight] %fails too

% Expected one output from a curly brace or dot indexing expression, 
% but there were 3 results. 

A:

If only the top level is a non-scalar structure array, and every entry below is a scalar structure, you can collect the leaves with a call to arrayfun, then do your calculation on the returned vector:
>> weights = arrayfun(@(s) s.properties.weight, apple)  % To get the vector

weights =

   300   330   340

>> someapples = mean(arrayfun(@(s) s.properties.weight, apple))

someapples =

  323.3333

The reason [apple.properties.weight] fails is because dot indexing returns a comma-separated list of structures for apple.properties.  You would need to collect this list into a new structure array, then apply dot indexing to that for the next field weight.