Material take-off refers to a list of material swith quantities and types for…
- User
Material take-off refers to a list of material swith quantities and types for construction. As one worker in the construction office, you just received one material take-off sheet for the past several months from the former worker, and one incomplete material take-off sheet for future months. (The numbers of past months and future months are both not fixed). When organizing all data in the first material take-off sheet, you store all materials’ quantities and total cost in order for the past several months as one cell array, “ptake”. One row represents one month. And materials’ names are stored in one extra string array, “materials”, like [“sand” “glass” “bricks”] in the same order as in “ptake”. Here is one example of input, “ptake”, you will get: sand glass brick total 23 56 22 2211 34 72 53 3707 65 43 72 4037 34 64 12 2178
For the second, material sheet, you only store quantities of all materials in the same order in the cell array, “ftake”, as the total cost is not calculated yet. So the input, “ftake”, is almost the same as “ptake” except the last column. In this question, you need to find out the unit cost of all materials first, and store them in the array, “ucost”. The order of the unit cost should follow the order of names in “materials”. Then you need to calculate the total cost for the future months. At last, you need to store materials’ quantity and total cost in the cell array, “ttake” like this: Material Month1 Month2 … cost “sand” 23 34 … 23523 “glass” 56 72 … 13232 “brick” 22 53 … 23287 Tips you have to use: if “ptake”‘s month is not enough for you to obtain the unit cost of material, then “ttake” should be “Info is not enough”. You are given the following code in matlab just fill it in: function [ucost, ttake] = takeoff(ptake, ftake, materials)
end. You should output “ucost” a 3x1 double representing materials’ unitcost. You should also output “ttake”.
- Assistant
function [ucost, ttake] = takeoff(ptake, ftake, materials) if size(ptake,1) < 2 ttake = "Info is not enough"; ucost = NaN; return end
ucost = sum(ptake(1:end-1,1:end-1))./sum(ptake(1:end-1,end)); total_cost_ftake = ftake(:,1:end-1)*ucost'; total_cost_ptake = ptake(:,end); ttake = [materials', num2cell([ptake(:,1:end-1); ftake(:,1:end-1)],2), num2cell([total_cost_ptake, total_cost_ftake],2); "cost", "", "", "", num2cell([sum(total_cost_ptake),sum(total_cost_ftake)])];end
- User
Error using sum Invalid data type. First argument must be numeric or logical.
Error in takeoff (line 8) ucost = sum(ptake(1:end-1,1:end-1))./sum(ptake(1:end-1,end));
- Assistant
This error message indicates that the data type of the input argument
ptakeis not numeric or logical, and therefore thesumfunction cannot operate on it.Based on the error message, it seems that
ptakeis not in the expected format. Please make sure thatptakeis a numeric matrix with numeric values for material quantities and total cost.If you need further assistance, please provide more details about how
ptakeis being created, or share the code that generatesptake. - User
the code that generates "ptake" is: ptake = {23 56 22 2211; 34 72 53 3707;65 43 72 4037; 34 64 12 2178};
- Assistant
The format of
ptakeseems to be incorrect.Based on your description,
ptakeshould be a numeric matrix with the dimensions (number of months) x (number of materials + 1), where the first n columns represent the quantities of each material for each month, and the n+1th column represents the total cost for each month.In the provided code
ptake = {23 56 22 2211; 34 72 53 3707;65 43 72 4037; 34 64 12 2178};,ptakeis a cell array with dimensions 4x4, where each cell contains a numeric value. This is not the expected format forptake.To fix this, you can convert
ptaketo a numeric matrix using thecell2matfunction:ptake = [23 56 22 2211; 34 72 53 3707; 65 43 72 4037; 34 64 12 2178];Now
ptakeshould be a numeric matrix with dimensions 4x4, representing the quantities of each material for each month, and the total cost for each month. - User
Undefined function 'mtimes' for input arguments of type 'cell'.
Error in takeoff (line 10) total_cost_ftake = ftake(:,1:end-1)*'ucost';
- Assistant
This error occurs because you are trying to perform matrix multiplication (
*) between a cell array (ftake(:,1:end-1)) and a string ('ucost'), which is not allowed.To fix this, you need to use the variable
ucost(which you defined earlier as a 3x1 numeric array) instead of the string'ucost'. Also, you should convertftake(:,1:end-1)to a numeric matrix before performing matrix multiplication, using thecell2matfunction:total_cost_ftake = cell2mat(ftake(:,1:end-1)) * ucost;Now the code should perform matrix multiplication correctly and avoid the error you encountered.
- User
give me the entire fixed solution
- Assistant
Sure, here's the fixed solution:
function [ucost, ttake] = takeoff(ptake, ftake, materials) if size(ptake,1) < 2 ttake = "Info is not enough"; ucost = NaN; return end ucost = sum(ptake(1:end-1,1:end-1))./sum(ptake(1:end-1,end)); total_cost_ftake = cell2mat(ftake(:,1:end-1)) * ucost'; total_cost_ptake = ptake(:,end); ttake = [materials', num2cell([ptake(:,1:end-1); ftake(:,1:end-1)],2), num2cell([total_cost_ptake, total_cost_ftake],2); "cost", "", "", "", num2cell([sum(total_cost_ptake),sum(total_cost_ftake)])]; endThis should fix the issues with the original code and allow it to compute the desired outputs.