Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Matlab function that converts calendar months (input as numbers, 1-12) to seasons (output as numbers, 1-4). Months 12 and 1-2 are season 1

Write a Matlab function that converts calendar months (input as numbers, 1-12) to seasons (output as numbers, 1-4). Months 12 and 1-2 are season 1 [winter], 3-5 are season 2 [spring], 6-8 are season 3 [summer], 9-11 season 4 [fall]. Have the function exit with an error (Matlab error()) if the input month is not an integer, or is not between 1 and 12. Include help text to tell users what the function does. Check the function with a valid input (such as 7) and an invalid input (such as 0).

function s = season(m) % Return the season corresponding to each calendar month (1-12). % The season should be an integer 1-4: % 1 (winter) for Dec-Jan_Feb, % 2 (spring) for Mar-Apr-May % 3 (summer) for Jun-Jul-Aug % 4 (fall) for Sep-Oct-Nov % The function should give an error if the input isn't an integer between 1 and 12

Hint: You can use an if...else...then statement, to set the value of the output season to 1-4 depending on the month, and to signal an error if the input month was not an integer or not between 1 and 12. Its also possible to use a switch...case statement to do the same thing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago