In: Computer Science
Please create a matrix A by extract the first 9 entries(first 9 rows) from Ownership(income&lot size) and first 9 entries(first 9 rows) from Non ownership(income& lotsize) by using matlab from the table below:
Income | Lot_Size | Ownership |
60 | 18.4 | owner |
85.5 | 16.8 | owner |
64.8 | 21.6 | owner |
61.5 | 20.8 | owner |
87 | 23.6 | owner |
110.1 | 19.2 | owner |
108 | 17.6 | owner |
82.8 | 22.4 | owner |
69 | 20 | owner |
93 | 20.8 | owner |
51 | 22 | owner |
81 | 20 | owner |
75 | 19.6 | non-owner |
52.8 | 20.8 | non-owner |
64.8 | 17.2 | non-owner |
43.2 | 20.4 | non-owner |
84 | 17.6 | non-owner |
49.2 | 17.6 | non-owner |
59.4 | 16 | non-owner |
66 | 18.4 | non-owner |
47.4 | 16.4 | non-owner |
33 | 18.8 | non-owner |
51 | 14 | non-owner |
63 | 14.8 | non-owner |
MATLAB CODE:
% Income vector
Income = [60, 85.5, 64.8, 61.5, 87, 110.1, 108, ...
82.8, 69, 93, 51, 81, 75, 52.8, 64.8, 43.2, 84, ...
49.2, 59.4, 66, 47.4, 33, 51, 63];
% Lot Size vector
Lot_Size = [18.4, 16.8, 21.6, 20.8, 23.6, 19.2, 17.6, 22.4, 20, ...
20.8, 22, 20, 19.6, 20.8, 17.2, 20.4, 17.6, 17.6, ...
16, 18.4, 16.4, 18.8, 14, 14.8];
% Ownership vector
Ownership = repelem(["owner", "non-owner"],12);
% Three vectors are stored into the Ownership Matrix
OwnershipData = [Income', Lot_Size', Ownership'];
countOwner = 0;
countNonOwner = 0;
A = []; % Matrix to store extracted entries (only column Income & Lot_Size)
for index = 1:length(OwnershipData)
if(OwnershipData(index, 3) == "owner")
% When 9 Ownership entries are added to the matrix A,
% it will stop adding any more entries
if(countOwner < 9)
A = [A; OwnershipData(index, 1:2)];
countOwner = countOwner + 1;
end
else
% When 9 Non Ownership entries are added to the matrix A,
% it will stop adding any more entries
if(countNonOwner < 9)
A = [A; OwnershipData(index, 1:2)];
countNonOwner = countNonOwner + 1;
end
end
end
The Ownership matrix will look like this:
OUTPUT:
MATRIX A =