Write a program to write a length conversion chart to a file. It will print lengths in feet, from 1 to an integer specified by the user, in one column and the corresponding length in meters ( 1 foot = 0.3048 m) in a second column
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:17.6
All Answers
total answers (1)
Ch6Ex17.m
% Write a length conversion chart to a file
% Call a function to get the max length in feet
maxl = promptMaxL;
% Call a function to write the chart to a file
lengthChart(maxl)
promptMaxL.m
function maxl = promptMaxL
% This function prompts the user for a max length in feet
% It error-checks to make sure it is a positive integer
% Format of call: promptmaxl or promptmaxl()
% Returns the integer maximum length in feet
inputnum = input('Enter the maximum length: ');
num2 = int32(inputnum);
while num2 ~= inputnum | num2 < 0
inputnum = input('Invalid! Enter a positive integer: ');
num2 = int32(inputnum);
end
maxl = inputnum;
end
lengthChart.m
function lengthChart(maxl)
% Creates a chart of converting feet to
% meters and writes it to a file
% Format of call: lengthChart(maximum length)
% Does not return any values
ft = 1:maxl;
meters = ft * .3048;
chart = [ft;meters]';
save ftmetchart.dat chart -ascii
end
need an explanation for this answer? contact us directly to get an explanation for this answer