We present a modelling approach for diffusion in a complex medium characterized by a random length scale. The resulting stochastic process shows subdiffusion with a behavior in qualitative agreement with single particle tracking experiments in living cells, such as ergodicity breaking, p-variation and aging. In particular, this approach recapitulates characteristic features previously described in part by the fractional Brownian motion and in part by the continuous-time random walk. Moreover, for a proper distribution of the length scale, a single parameter controls the ergodic-to-nonergodic transition and, remarkably, also drives the transition of the diffusion equation of the process from non-fractional to fractional, thus demonstrating that fractional kinetics emerges from ergodicity breaking.