In MATLAB Loop/Array Test Practice 1 A data scientist is writing a program to so
ID: 3595757 • Letter: I
Question
In MATLAB
Loop/Array Test Practice 1 A data scientist is writing a program to sort through a data set on temperature. She has long arrays of temperature data, and corresponding arrays of the time the temperature data was collected. These arrays are of equal length. The data scientist only cares about the times that the temperature drops below freezing, and wants to create a simplified representation of that data in a new array. Put yourself in the data scientist's shoes. Write a function that takes two inputs, an array of temperatures, and an array of times. Your function should return a new array of all of the times that the temperature drops below freezing. Assume that temperature is in degrees Celsius, and that the times are stored in a numeric format (i.e., the time array is an array of numbers). For example, with the arrays: Temp = 20 148-1-410-581; Time = [1000 1100 1200 100 200 300 400 500 600]; Your function would return: Output = [100 200 500]Explanation / Answer
Save this in file getFreezingTime.m
function output = getFreezingTime(temp, time)
output = [];
lengt = size(temp, 2);
for i = 1:lengt
if temp(i) < 0
output = [output time(i)];
end
end
end
% for testing
put this in console to match output
getFreezingTime([20 14 8 -1 -4 1 0 -5 8], [1000 1100 1200 100 200 300 400 500 600])
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.