The following code:
\documentclass{article}
\usepackage[framed,numbered,autolinebreaks]{mcode}
\usepackage{filecontents}
\begin{filecontents*}{example_function.m}
% create a function for mass of spherical particle
fxn_mass_from_density_radius = @(rho, x) 4/3 .* pi .* (x(:)^3) .* rho;
% density
rho = 1000; % kg m^{-1}
% define radius
r = 1e-6; % m
% compute particle mass
m = feval(fxn_mass_from_density_radius, rho_particle, r); % kg
\end{filecontents*}
\setlength{\parindent}{0pt}
\begin{document}
In the code below we define a function and two variables
\lstinputlisting[firstline=1,lastline=8]{example_function.m}
\addvspace{5mm}
In the code below we evaluate the function
\lstinputlisting[firstline=10,lastline=11]{example_function.m}
\addvspace{5mm}
\end{document}
results in the following output
Note that there are two framed boxes, one source code file. Note also that the rendered line numbers both start at 1.
I think that the minimal bit of information that the author should have to provide is the start and end line numbers. I'd like to avoid having to manually handle the offset. I'm wondering if the listings package can accommodate this?

linerangespecification – Werner Nov 13 '18 at 19:32