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

See below picture: The above matrix \"Cheapest\" is not formatted how I would li

ID: 672840 • Letter: S

Question

See below picture:

The above matrix "Cheapest" is not formatted how I would like it to be formatted.

I would like the first row to be displayed as integers like so (1 3 3 1 3).

How do I make just the top row display as integers without decimal places? I want the second row of "Cheapest" to display decimals as is.

format bank; VendCost =[[1.2,52.8,-1,44.7,5.2];(99.37,1,22,54,42];[8.4,6.4,.28,97, .54]]; [ row, column] = size (vendCo3t) ; Cheapest zeros (2, column) ; min!ndex=1; minv 3- 6- VendCost (1,1 ) ; for for j=1 : column i=1 : row 10 if (VendCost (i,j) -1) 12 13 14-1 m!nIndex = 1; if (VendCost (i,j)

Explanation / Answer

format bank;
VendCost = [[1.2, 52.8, -1,44.7,5.2];[99.37,-1,22,54,42]; [8.4,6.4,0.28,97,0.54]];
[row,column] = size(VendCost);
Cheapest = zeros(2,column);
minIndex = 1;
minv = VendCost(1,1);

for j = 1:column
   for i = 1:row
       if (VendCost(i,j) ~= -1)
           if (VendCost(i,j) < minv)
               minv = VendCost(i,j);
               minIndex = i;
           end
       end
   end
   if (minv ~= 1)
       Cheapest(1,j) = minIndex;
       Cheapest(2,j) = minv;
   end
   minIndex = 1;
   minv = VendCost(1,2);
end

VendCost
temp = size(Cheapest);
fprintf('Cheapest = ');
for i = 1:temp(:,1)
   fprintf(' ');
   for j = 1:temp(:,2)
       if (i == 1)
           fprintf('%d ',int64(Cheapest(i,j)));
       else
           fprintf('%.2f ',Cheapest(i,j));
       end
   end
   fprintf(' ');
end