In a bolt manufacturing plant, samples are taken and the length of each sample m
ID: 3779895 • Letter: I
Question
In a bolt manufacturing plant, samples are taken and the length of each sample measured. Write a function named BoltTol that accepts three parameters: A variable named Length containing the nominal (desired) length of the bolts. A matrix named BoltData containing the measurements of all samples. A variable named Tol containing a desired tolerance in percent. Your function should return a matrix TolError# with the same size as BoltData in which each element is either -1, 0, or 1, where zero indicates the corresponding bolt Is within the tolerance specified, -1 indicates too short, or 1 indicates too long. Example: If Length = 1 (in) and tolerance = 5, bolts between 0.95 inches and 1.05 inches would be coded as 0. bolts shorter than 0.95 inch would be coded -1, and bolts longer than 1.05 inches would be coded 1.Explanation / Answer
Matlab function code:
function [ TolErrors ] = BoltTol( Length,BoltData,Tol )
[m,n]=size(BoltData);
TolErrors=zeros(size(BoltData));
for i=1:n
error=BoltData(i)-Length;
t=Tol/100;
if error<-t
TolErrors(i)=-1;
elseif error>t
TolErrors(i)=1;
else
TolErrors(i)=0;
end
end
end
output;
>> Length=1
Length =
1
>> BoltData=[0.95 0.90 0.85 0.80 1.05 1.0 1.1]
BoltData =
0.9500 0.9000 0.8500 0.8000 1.0500 1.0000 1.1000
>> Tol=5.0
Tol =
5
>> BoltTol( Length,BoltData,Tol )
ans =
-1 -1 -1 -1 1 0 1
>> BoltData=[0.96 0.90 0.98 0.80 1.04 1.0 1.1]
BoltData =
0.9600 0.9000 0.9800 0.8000 1.0400 1.0000 1.1000
>> BoltTol( Length,BoltData,Tol )
ans =
0 -1 0 -1 0 0 1
>>