Question
Use matlab. Due in 1 hour. Need done quicky and correctly

%{ The following vector of structures stores data for a test batch of camshafts that will be used in a new testbed engine des

Using a loop and a conditional statement, create a code that loops through the vector of structures and prints a list of the
%} 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


0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Use matlab. Due in 1 hour. Need done quicky and correctly %{ The following vector of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT