clear all, clc;
% Matlab script to display the details of camshafts whose critical
diameters are within the error tolerance
% define the structure vector
cs(1) =
struct('ID',"CS-01",'cd_1',3.45,'cd_2',17.14,'cd_3',245.18);
cs(2) =
struct('ID',"CS-02",'cd_1',3.41,'cd_2',17.16,'cd_3',245.13);
cs(3) =
struct('ID',"CS-03",'cd_1',3.45,'cd_2',17.18,'cd_3',245.15);
cs(4) =
struct('ID',"CS-04",'cd_1',3.47,'cd_2',17.13,'cd_3',246.00);
cs(5) =
struct('ID',"CS-05",'cd_1',3.43,'cd_2',17.15,'cd_3',245.16);
cs(6) =
struct('ID',"CS-06",'cd_1',3.41,'cd_2',17.14,'cd_3',245.17);
cs(7) =
struct('ID',"CS-07",'cd_1',3.49,'cd_2',17.13,'cd_3',245.15);
cs(8) =
struct('ID',"CS-08",'cd_1',3.43,'cd_2',17.18,'cd_3',245.13);
cs(9) =
struct('ID',"CS-09",'cd_1',3.45,'cd_2',17.16,'cd_3',245.22);
cs(10) =
struct('ID',"CS-10",'cd_1',3.42,'cd_2',17.14,'cd_3',245.20);
% display the heading
fprintf('%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n','ID','CD 1','CD
2','CD 3','Error CD1','Error CD2','Error CD3');
% loop over the structure vector
for i=1:length(cs)
% calculate the absolute error value for each critical
diameter
error_cd_1 = abs(cs(i).cd_1 - 3.45);
error_cd_2 = abs(cs(i).cd_2 - 17.14);
error_cd_3 = abs(cs(i).cd_3 - 245.18);
% if all absolute errors are within tolerance limits,
display the
% camshaft
if((error_cd_1 <= 0.040) && (error_cd_2 <= 0.020)
&& (error_cd_3 <= 0.050))
fprintf('%-10s%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f\n',cs(i).ID,cs(i).cd_1,cs(i).cd_2,cs(i).cd_3,
error_cd_1, error_cd_2, error_cd_3);
end
end
%end of script
Use matlab. Due in 1 hour. Need done quicky and correctly %{ The following vector of...