Question

using Function Name: hahaYes Inputs: 1. 2. (char) The filename of an Excel file containing word counts from various works (cell) AMATLAB

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The output mentioned in the question as an example is not correct according to the question as the absolute error is found the minimum for work 'Survivor' (1 for Redemption and 4 for Island) twice and then 'Drag Race' (5 for Redemption). Also, there is a clash between how the input is expected in the question(example: input is said to be a 2XN cell in written but in the example code it is given as an NX2 cell). There are a lot of such ambiguities in the question. The required code is given below:

function out = hahaYes(File_name,Cell)

% reads the values in matrix A and the heading in text
[A text] = xlsread(File_name);

% to calculate size of the Cell that is given as input
[r_cell c_cell] = size(Cell);

% to calculate size of the matrix A
[r_excel c_excel] = size(A);

l = 1;

% logic to calculate the absolute error
for i = 1:r_cell
for j = 2:c_excel+1
if strcmp(Cell{i,1},text{1,j}) == 1
pos_excel(l) = j;
l = l+1;
for k = 1:r_excel
data(k,i) = abs(Cell{i,2} - A(k,j-1));
end
end
end
end


min1 = Inf;
min2 = Inf;
min3 = Inf;
pos = zeros(3,2);

% To find the position of first minimum
for i = 1:r_cell
for j = 1:c_cell
if data(i,j) < min1
min1 = data(i,j);
pos(1,1) = i;
pos(1,2) = j;
end
end
end

% To find the position of second minimum
for i = 1:r_cell
for j = 1:c_cell
if data(i,j) < min2 && data(i,j) > min1
min2 = data(i,j);
pos(2,1) = i;
pos(2,2) = j;
end
end
end

% To find the position of third minimum
for i = 1:r_cell
for j = 1:c_cell
if data(i,j) > min2 && data(i,j) < min3
min3 = data(i,j);
pos(3,1) = i;
pos(3,2) = j;
end
end
end

% returning the output
for i = 1:3
out{i,1} = text{pos(i,1)+1,1};
end

end

Add a comment
Know the answer?
Add Answer to:
Function Name: hahaYes Inputs: 1. 2. (char) The filename of an Excel file containing word counts ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT