You are assessing the price of various components from diffe

You are assessing the price of various components from different vendors and wish to find the least expensive vendor for each component. The prices of the parts from each vendor are stored in a matrix, VendCost. Each row corresponds to a specific vendor and each column corresponds to a specific component. If a specific part is not offered by a vendor, the corresponding entry will be -1.

Write a program that will determine which vendor offers the cheapest price for each component, and place the results in a two-row matrix Cheapest with the same number of columns as there are columns in VendCost. Each entry in the first row of Cheapest should be an integer corresponding to the row number of the vendor with the cheapest price for the corresponding component, and the entries in row #2 should contain the lowest price for that component. You may assume that each part is available from at least one of the listed vendors. If two or more vendors offer a component at the same lowest price, you may choose either one.

You may not use the built-in min function or other similar functions to solve this problem. You may not use direct matrix operations to solve this problem; you must do it using for loops (in a meaningful way). Your solution must work for any number of vendors and any number of components.

Must be done on MATLAB.

Example:

VendCost =

4.97 8.54 2.04 0.44 13.55 -1.00

5.23 8.23 2.12 0.39 15.98 2.67 5.24

8.22 2.09 0.51 -1.00 2.76

Cheapest =

1 3 1 2 1 2

4.97 8.22 2.04 0.39 13.55 2.67

Solution

vendors = input(\"how many vendors are there\"); % user to input the number of vendors

products = input(\"how many products are there\"); % user to input the number of products

c = cell(vendors,products); % it will create a 2D array with vendors as rows and products as columns

d = cell(minindices); %it will store the minimum values of the indices to buy

for a=0:vendors

{

for b=0:products

{

value = input(cost of item);

c[a][b] = value;

}

}

f = 1000;

for a=0:vendors

{

for b=0:products

{

if(c[a][b] < d[b] && c[a][b]!=-1)

d[b] = c[a][b];

}

disp(b,d[b]);

}

You are assessing the price of various components from different vendors and wish to find the least expensive vendor for each component. The prices of the parts
You are assessing the price of various components from different vendors and wish to find the least expensive vendor for each component. The prices of the parts

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site