MATLAB: Write a script that will prompt the user for the month of interest. caseexception statementfunctioninputpromptscriptswitch Best Answer Don't have the function keyword since it's supposed to be a script. You need to do something like theMonth = input('Enter a month: ','s'); switch lower(theMonth) case {'dec', 'jan', 'feb'} season = 'Winter'; case {'mar', 'apr', 'may'} season = 'Spring'; case {'jun', 'jul', 'aug'} season = 'Summer'; case {'Sep', 'oct', 'nov'} season = 'Autumn'; otherwise season = 'Unknown'; end fprintf('%s is a month in %s.\n', theMonth, season) Related SolutionsMATLAB: How to define a new variable in a table, Part 2 Try thisT = % you tableMonths = {'January', 'February', 'March', 'April', 'May', 'June', ... 'July', 'August', 'September', 'October', 'November', 'December'}.';Mnth2Season = [1 1 1 2 2 2 3 3 3 4 4 4].'; % for exampleSeasons = {'Winter', 'Spring', 'Summer', 'Autumn'}.';[~, idx] = ismember(T.Months, Months);T.Season = Seasons(Mnth2Season(idx)); MATLAB: Program not running correctly. Trying to write program to determine number of days in month. ...switch (month) case {1,3,5,7,8,10,12} days = 31; case {4,6,9,11} days =30; case 2 days=28 + leap_year;endBTW, trytype eomdayat command line... :) Related QuestionHow to filter tables in the cellFast subsetting or indexing of dataHow to i generate monthly sequenceHow to modify this code for calculation seasonal values for each year (not all years)
Best Answer