matlab Write a MATLAB code that loads Income_Info.txt and determines the followi
ID: 2080941 • Letter: M
Question
matlab
Explanation / Answer
Since solution is asked for question 2, 4 and 5 and they are different questions, I am providing the code for 2 with all its 4 different sub-parts.
Solution:
First create the text file income_info.txt and the file contains 3 columns.
Col 1---> Employee Code
Col 2 --> Hourly Fixed Pay
Col 3 --> Work Hour Daily
Col 4 -->Personal Tips Weekly
income_info.txt
17052 20 8 12
17053 20 8 18
17054 20 8 10
Then import the file in MATLAB.
THE M SCRIPT FILE IS GIVEN BELOW:
clc
disp('The total number of employees working in the cafe is')
disp(length(income_info(:,1)))
m=length(income_info(:,1)); % It stores the information about number of employees working=Number of rows
earning=zeros(m,1); % It will store the information about the earning of each employee
disp(length(income_info(1,:))) %Max row and col length for the income_info matrix
for i=1:m
earning(i,1)=income_info(i,2)*income_info(i,3)+income_info(i,4);
end
%After this poing all the employee's salary of the week has been calculated
% 2(a)and 2 (b) Display of Higherst Weekly Pay & corresponding empolyee
% number
if(earning(1,1)> earning(2,1))
if(earning(1,1)> earning(3,1))
disp('Highest Salary is')
disp(earning(1,1))
disp('The employee earning highest salary is')
disp(income_info(1,1))
end
end
if(earning(2,1)> earning(1,1))
if(earning(2,1)> earning(3,1))
disp('Highest Salary is')
disp(earning(2,1))
disp('The employee earning highest salary is')
disp(income_info(2,1))
end
end
if(earning(3,1)> earning(2,1))
if(earning(3,1)> earning(1,1))
disp('Highest Salary is')
disp(earning(3,1))
disp('The employee earning highest salary is')
disp(income_info(3,1))
end
end
% 2(c) & 2(d)
if(earning(1,1)< earning(2,1))
if(earning(1,1)< earning(3,1))
disp('Lowest Salary is')
disp(earning(1,1))
disp('The employee earning lowest salary is')
disp(income_info(1,1))
end
end
if(earning(2,1)< earning(1,1))
if(earning(2,1)< earning(3,1))
disp('Lowest Salary is')
disp(earning(2,1))
disp('The employee earning lowest salary is')
disp(income_info(2,1))
end
end
if(earning(3,1)< earning(2,1))
if(earning(3,1)< earning(1,1))
disp('Lowest Salary is')
disp(earning(3,1))
disp('The employee earning lowest salary is')
disp(income_info(3,1))
end
end
The Output:
The total number of employees working in the cafe is
3
4
Highest Salary is
178
The employee earning highest salary is
17053
Lowest Salary is
170
The employee earning lowest salary is
17054
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.