A script that calls another script

A student writes tank_mass.m to find the volume and mass of fuel oil in a vertical cylindrical tank. The third line runs an older script, tank_defaults.m, from the same folder to load the oil density. Both files are shown below. The student runs tank_mass with an empty workspace.


MATLAB
% tank_mass.m
r = 1.5;              % tank radius, m
h = 4;                % oil depth, m
tank_defaults         % runs tank_defaults.m
V = pi*r^2*h;         % oil volume, m^3
m = rho*V;            % oil mass, kg
fprintf('V = %.2f m^3, m = %.0f kg\n', V, m)


MATLAB
% tank_defaults.m
rho = 850;            % fuel oil density, kg/m^3
r = 1.2;              % default radius used in an earlier project, m


Enter the volume printed by the fprintf line in cubic metres to two decimal places. Enter the printed mass in kilograms to the nearest kilogram. Enter the value of r left in the workspace after the run, in metres, to one decimal place.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More MATLAB Scripts (M-files) Questions: