In tableData the column variable of the first column should be RowerNames, the second RowingEvent, the third RowerWeight and the fourth WeightCategories. The data class of the values in

1.RowerNames column should be string scalars
2.RowingEvent column should should be string scalars
3.RowerWeight column should be double, and
4.WeightCategories column should be a discretized categorical array.

Respuesta :

Answer:

Required MatLab code is given below:

Explanation:

function tableData=CreateTable(Names, Event, Weight)

% Matlab function to create a table from the given input arrays

% Inputs:

% Names will be n x 1 string array,

% Event will be n x 1 string array,

% Weight will be n x 1 double column array.

% Outputs:

% tableData : where column variables are : RowerNames, RowingEvent,

% RowerWeight and WeightCategories

WeightCategories = ""; % create an empty WeightCategories array

% loop over the Weight column array, populate the WeightCategories

% based on Weight

for i=1:length(Weight)

if(Weight(i) >= 100 && Weight(i) < 150)

WeightCategories(i) = "light weight";

elseif(Weight(i) >= 150 && Weight(i) < 200)

WeightCategories(i) = "medium weight";

else

WeightCategories(i) = "heavy weight";

end

end

% create the table with arrays Names, Events, Weight and

% WeightCategories by taking transpose of WeightCategories as WeightCategories is a row array

tableData = table(Names,Event,Weight,WeightCategories','VariableNames',{'RowerNames','RowingEvent','RowerWeight','WeightCategories'});

end

%end of function