Clear Filters
Clear Filters

Logical functions: functions

1 view (last 30 days)
Azola Feni
Azola Feni on 25 Feb 2021
Commented: Steven Lord on 25 Feb 2021
Question 1 Use part of the program you created for assignment three to create a MATLAB program that will load the Excel file named weather.xlsx found under Shared Documents on the SharePoint site into MATLAB by means of the xlsread function and name it weather_data. Your program should consist of a MATLAB program AND MATLAB function that will perform the following tasks from the loaded data: a) Extract only the first three columns from the spreadsheet into separate arrays and save them as month, Temp_high and Temp_low. These values must be used to determine the maximum and minimum temperatures for the year for the city of Cape Town which will be performed in your MATLAB function explained in part (b) below. To determine the maximum and minimum values in your MATLAB function, all three variables must be declared as global variables in your M-file. b) Create a MATLAB function named weather which uses month, Temp_high and Temp_low as inputs. Determine the maximum_temp, minimum_temp as well as the months in which they occurred in (defined as month_max_temp, month_min_temp). c) Set maximum_temp and minimum_temp as the outputs of your function. d) Define month_max_temp and month_min_temp as global variables and call them along with your function into your M-file. e) Create a plot of the data from parts (a) to (d) as indicated in figure 2, and display the information in the Command Window as indicated in figure 1 below. Plot the high and low temperatures in red and blue with a line thickness of 1.5, as well as the maximum value as a green asterisk, and the minimum temperature as a magenta circle. Also equip your plot with the necessary title and axis labels. Your plot must also contain a legend at the location as indicated in figure 2 and should ONLY display the maximum and minimum data points
  1 Comment
Steven Lord
Steven Lord on 25 Feb 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
By the way, tell your professor:
To determine the maximum and minimum values in your MATLAB function, all three variables must be declared as global variables in your M-file.
In general, the experts on MATLAB Answers discourage the use of global variables. They can cause problems that are difficult to debug. Your code's answers may change due to something happening in a completely different file.

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!