This is a bug in the code generation version of RANDSAMPLE. The compiler is complaining about a situation that it really doesn't need to complain about, as the edges variable is never referenced unless it is first defined as far as I can tell. It's just challenging to infer that from a static analysis.
I'll create an internal bug report for this to get it fixed. It's really just a matter of providing an initialization for edges even when w is empty (e.g. adding
edges = zeros('like',w);
before the "end" on line 66 of matlab/toolbox/stats/eml/randsample.m. I mean, that's completely unsupported, and I'm not recommending it. You'd be doing that at your own risk. Really. Who knows what might happen?).