Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

must be in matlab!! and please you cant use find or sort i believe they want us

ID: 3184698 • Letter: M

Question

must be in matlab!! and please you cant use find or sort i believe they want us to use for or while loops but im not sure

Water customers must know their Average Winter Consumption (AWC) in order to calculate their water bill. The AWC is the a between September and February. This value will differ between customers. AWC values are update AWC that is then used for calculation of water charges for the nextyear e amount of water that a customer uses d every March. The da ta from the previous yea r is used for calculation of the The utility company stores the water usage data in a matrix form for its customers (each customer represented by a number 1,2, 3,.. etc). The first column carries information about the customer (numbers 1, 2, 3,., the second column is information about the month (numbers 1-12 representing the months January to December respectively) and the third column is the amount of water used in that month in kgals. However, due to an error in the system the data for the three customers got mixed up so that the chronology in the rows is lost. Write a function M-file that will accept the input data that consists of jumbled-up information about three customers as described above. The outputs to your function should be the three AWC values for the three customers (output A is AWC for customer 1, output B is AWC for customer 2, and output C is AWC for customer 3. Do not use the built-in functions, sort, or find, that work on an entire array A part of the data is shown on the right. 71 [A, B,C)=AIC (data) 3.3243 15.1137 22.4133 >> 21 28 52 ut Restrictions: The function should halt and return a red error message if the following conditions are not met: The input data must have size 36 x 3 The first column of data must consist of only 1, 2, or 3. . .The second column of data must consist of integers between 1 and 12. . The third column of data must be positive numbers (including 0).

Explanation / Answer

matlab code

close all
clear
clc

data = zeros(36,3);
data(:,1) = randi(3,36,1);
data(:,2) = randi(12,36,1);
data(:,3) = 100*rand(36,1);
[A,B,C] = AWC(data)

function [A,B,C] = AWC(data)
A = []; B = []; C = [];
for i=1:size(data,1)
if data(i,1) == 1
A = [A, data(i,3)];
elseif data(i,2) == 2
B = [B, data(i,3)];
else
C = [C, data(i,3)];
end
end
A = mean(A);
B = mean(B);
C = mean(C);
end

sample output

A =
55.5722
B =
36.9158
C =
49.0041