Part 2: MATLAB Exercise 1 (50 pts) Write a program that tells the user if a city...

50.1K

Verified Solution

Question

Mechanical Engineering

Part 2: MATLAB

Exercise 1 (50 pts)

Write a program that tells the user if a city of their choice isin a tropical, temperate, or polar region. Use the cities.txt fileprovided in the Files section of this class. Your program shouldread the data in that file, find the city given by the user, andreturn a text message with the information. If the city is notfound, your program should write a message accordingly. To decidewhich region each city falls into, use the table below.

LatitudeRegion
Above 66 NPolar
Between 35 N and 66 NTemperate
Between 35 S and 35 NTropical
Between 35 S and 66 STemperate
Below 66 SPolar

HINT: If you follow the file reading methods explained in ourvideo tutorial, your data will be in cell format. There are a fewfunctions that could be very useful in this case: strcmpcompares two strings (one of which can be in a cell) to see if theymatch. Also, cell2mat converts a cell array into anordinary array. Finally, find finds indices and values ofany non-zero elements in an array.

See the output examples below:

What city are you interested in? CaracasCaracas is in a tropical region What city are you interested in? MercedCity not found! 

https://catcourses.ucmerced.edu/files/1587454/download?download_frd=1

Answer & Explanation Solved by verified expert
4.3 Ratings (967 Votes)
clc declaring filenamefilename citiestxt reading filedata readFilefilename declaring latitude arraylatitude getting citiescities lowerdata3reading the latitudes and storing in the variablesfor ii 1numeldata1tokens    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students