Matlab Question:
Important! Read: No for or while loops may be used; must use the disp function
The top speeds of sportscars, given in miles per hour, are:
155 mph BMW M5
217 mph Lamborghini Aventador Spyder
205 mph Ferrari 488
205 mph Nissan GTR
197 mph Chevrolet Corvette Stingray ZR1
258 mph Bugatti Veyron Supersport
195 mph Dodge Viper
270 mph Hennessey Venom
155 mph BMW M3
195 mph Mercedes SL
Write a function selectCars to identify cars with top speed within a given range and display the identified names. The selected cars speed will be in a range given by lowerBound < speed < upperBound. Inputs to the function selectCars are a column array topSpeeds that lists of top speeds, the corresponding column array carNames with car names, and lowerBound and upperBound both given in km/h.
Given:
To display the selected carNames, for example the first two, use something analogous to disp(carNames(1:2,:))
1 mile = 1.609 kilometers
Test data sets for topSpeeds and carNames (provided in example function call)
Restriction: For and while loops may not be used.
The function call is:
function identifiedCars=selectCars( topSpeeds, carNames, lowerBound, upperBound)
For example:
selectCars( topSpeeds, carNames, 287,338)
produces:
Ferrari 488
Nissan GTR
Chevrolet Corvette Stingray ZR1
Dodge Viper
Mercedes SL
![Your Function Save CReset MATLAB Documentation 1 function identifiedCars-selectCars( topSpeeds, carNames, lowerBound, upperBound) 2 % select cars that have top speed within a given range and display the names to the command line. 4% Inputs: column array topSpeeds with top speeds in mile/hour, corresponding column string array carNames with the car names lowerBound and upperBound in km/h 7% 8 9 % Your code goes here % 10 11 end Code to call your function Reset 1 topSpeeds [155; 217; 205 ;205 ;197 ;258 ;195;270;155; 195]; 2 carNames-charBMW M5, Lamborghini Aventador Spyder,... Ferrari 488,.. . Nissan GTR,... Chevrolet Corvette Stingray ZR1,.. . Bugatti Veyron Supersport.. Dodge Viper,... Hennessey Venom, BMW M3,.. . Mercedes SL; 4 5 7 9 10 12 lowerBound =200; upperBound-280; 13 [ identifiedCars ] = selectCars( topSpeeds, carNames, lowerBound, upperBound);](http://img.homeworklib.com/questions/e2136190-fc97-11eb-b19c-8f30e59851c0.png?x-oss-process=image/resize,w_560)
Function Implementation:

Sample Output 1: (lowerBound=287 and
upperBound=338)
Input:

Output:

Sample Output : (lowerBound=200 and upperBound=280)
Input:

Output:

CODE TO COPY:
function identifiedCars = selectCars( topSpeeds, carNames,
lowerBound, upperBound)
% select cars that have top speed within a given range
% and display the names to the command line.
% Inputs: column array topSpeeds with top speeds in
mile/hour,
%
corresponding column string array carNames with the car names
%
lowerBound and upperBound in km/h
% convert the topSpeeds from mile/hour to
km/h
topSpeeds = topSpeeds*1.609;
% find the logical index array for the desired
cars
logicalIndexArray = topSpeeds > lowerBound
& topSpeeds < upperBound;
% identify the car names that have top speed
within a given range
identifiedCars =
carNames(logicalIndexArray,:);
% display the car names to the command
line
disp(identifiedCars);
end
Matlab Question: Important! Read: No for or while loops may be used; must use the disp...