A machine cuts N pieces of a pipe. After each cut, each piece of pipe is weighed and its length is measured; these 2 values are then stored in a file called pipe.dat (first the weight and then the length on each line of the file)
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:5| Question number:12.5
All Answers
total answers (1)
Ch5Ex12.m
% Counts pipe rejects. Ignoring units, each pipe should be
% between 2.1 and 2.3 in weight and between 10.3 and 10.4
% in length
% read the pipe data and separate into vectors
load pipe.dat
weights = pipe(:,1);
lengths = pipe(:,2);
N = length(weights);
% the programming method of counting
count = 0;
for i=1:N
if weights(i) < 2.1 || weights(i) > 2.3 || ...
lengths(i) < 10.3 || lengths(i) > 10.4
count = count + 1;
end
end
fprintf('There were %d rejects.\n', count)
need an explanation for this answer? contact us directly to get an explanation for this answer