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

IT SHOULD USE MATLAB PLEASE USE MATLAB I am introducing a simpler version of thi

ID: 3829364 • Letter: I

Question

IT SHOULD USE MATLAB

PLEASE USE MATLAB

I am introducing a simpler version of this problem more appropriate to the course. You only need to complete one of these problems for full credit on hw10. Given an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element). The first row is always descriptive text. So if the input cell array s is | s = {... 'Day Temp' '1 -5' '2 19' '3 1' '4 9999' '5 3'}; then the output variable t is the following row vector. | t = [-5 19 1 2 3];

Explanation / Answer

function finalData = parseData(inputData)
    finalData = [];
  
    tempValues = [];
    interpTempValues = [];
  
    xValues = [];
    missingXValues = [];
  
    % Parse the input data, get Column-2
    % and interpolate the missing vlaues  
  
    for i=2:length(inputData)
  
        % Get column-2 data
        rowData = strtrim(cell2mat(inputData(i)));
        splittedData = strsplit(rowData);  
        Xval = str2num(cell2mat(splittedData(1)));
        tempVal = str2num(cell2mat(splittedData(2)));
      
        if (tempVal == 9999)
            missingXValues = [missingXValues Xval];
            continue;
        end
      
        tempValues = [tempValues tempVal];
        xValues = [xValues Xval];
    end

    % Interpolate the missing values  
    for i=1:length(missingXValues)
        interpTempValues = [interpTempValues interp1(xValues, tempValues, missingXValues(i))];              
    end
  
    % Copy back the entire data into finalData vector
    for i=1:length(xValues)
       finalData(xValues(i)) = tempValues(i);
    end
    for i=1:length(missingXValues)
        finalData(missingXValues(i)) = interpTempValues(i);
    end
  
end  


inputData = {'Day Temp', '1 6', '2 8', '3 10', '4 9999', '5 15'};
finalData = parseData(inputData)

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