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

Function Name: walmart Inputs: 1. (struct) A 1XM structure array with fields ‘It

ID: 664974 • Letter: F

Question

Function Name: walmart
Inputs:
1. (struct) A 1XM structure array with fields ‘Item’ and ‘Cost’
2. (cell) An Nx2 cell array with item names in the first column and their costs in the second column
Outputs:
1. (struct) The updated structure array with the item names alphabetized and the replacement costs implemented
Function Description:
You are a manager at your local Walmart and have just recently started experiencing a massive decline in sales. To your dismay, you discover that a Target has opened up down the street and is selling several items at very competitive prices. Determined to prove yourself as the manager of the best general goods retailer in town, you’ve compiled a list of the items that have a lower price tag at Target, as well as the price that’s beating yours out. All you have to do now is update your own item list so you can match Walmart’s prices to those of Target. That’d be a lot of work to do by hand, but, luckily, you can write a MATLAB function to do this for you!
Write a function that takes in a structure array with fields ‘Item’ and ‘Cost’ and an Nx2 cell array containing a list of the items that are cheaper at Target in the first column and their respective costs from Target in the second column. Sort the structure array into alphabetical order by item name. Then go through the structure array and replace the cost of each item that also appears in the cell array with its associated cost in the cell array.
Notes:
It may be useful to check how the sort() function works on cell arrays.
The prices listed in the cell array are guaranteed to be lower than the ones listed in the original structure.
The list of Target’s items is not guaranteed to be in alphabetical order.
The structure of Walmart’s items and the cell array of Target’s items are not guaranteed to be the same length.

Explanation / Answer

struct tag_cost
{
data type var_cost1;
data type var_cost2;
data type var_cost3;
};