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

I have attempted this problem several different ways including creating my own f

ID: 3915978 • Letter: I

Question

I have attempted this problem several different ways including creating my own function, which correctly runs the code and outputs the necessary string; however, when I copy and paste that correct code into the HW file and run the pretest it tells me that my answers for variables: G,H,I,and J are incorrect.

I have tried debugging and always end up with the correct output (when using my own function just can't get the pretest to recognize my answers)

Have I misunderstood what answers the HW Question is asking for?

Initially, I got very confused right here (See HW Additional instructions below):

I am hoping for some help debugging. Please help! (See My Function code below)

Thanks!

ABCs Structure Arrays Practice Function Name: socialMedia Inputs 1. (structure) A 1xN structure array containing fieldnames and data Outputs 1. (string) Which social media you are most addicted to Function Description Since coming to college, you have noticed that you are getting more and more addicted to social media. You decide that you are going to figure out which social media you are most addicted to and quit it cold turkey To figure out which one to quit you decided to write a MATLAB function. Write a function called socialMedia), which will take in a 1xN structure array, where each structure element represents a different day spent on social media and where each field represents a different social media. Each field in each structure will contain a double value representing how many hours you spent on that social media on that particular day in that order For example, you might have a 1x2 structure array which looks like: sa(1) sa (2) Facebook: 2 Twitter: 1 Facebook: 2 Twitter: 2 MATLABCentral: 22 MATLABCentral: 10 The social media with the most total hours over the span of the N days is the one you are most addicted to, and should be outputted. You should output the name of the social media exactly exactly as how it is represented by its field name Notes The structure array can be of any length There can be any number of fields in the structure array . .

Explanation / Answer

In the question, you have shown only descriptions of G and vec... but H, I, J are not described. Based on the question and your existing code, I have tried to code for H, I, J. Let me know in case you still have some issues. But please give descriptions of H, I, J as mentioned in question. If the answer helped, please do rate the answer. Thank you.


function[J] = socialMedia(sa2)
F = fieldnames(sa2);
G = [];
for n = 1:length(F)
field = F{n};
vec = [sa2.(field)];
G = [G; vec];
end
H = sum(G'); %transpose G since data for each media is a row, but sum() does it column wise
I = find(H == max(H));
J = F{I};
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote