month number to month name function

Create a Matlab function

4 Commenti

Rik
Rik il 23 Apr 2020
Copy of question:
Title:
month number to month name function
Body:
Create a Matlab function that is given the month number as input and the function outputs the name of the month in the text variable month_name
Rik
Rik il 23 Apr 2020
In response to your flag: your question is not unclear. If you didn't want your homework visible for your teacher to find you shouldn't have posted it.
madhan ravi
madhan ravi il 23 Apr 2020
Modificato: Rik il 23 Apr 2020
[expletive] why would you do that? So annoying when people do this. So when you ask something online isn’t that obvious that it’ll visible for everyone?? Come on!!
Name of Original OP: miika k
I am adding this to discourage such spamming behavior.

Accedi per commentare.

Risposte (2)

This snippet should do it using existing functions.
month_number = 11;
month_name = datestr(datetime(1,month_number,1),'mmmm');
If you want it as a function just add a function header
function month_name = month_number2name(month_number)
month_name = datestr(datetime(1,month_number,1),'mmmm');
Ameer Hamza
Ameer Hamza il 23 Apr 2020
Modificato: Ameer Hamza il 23 Apr 2020
This is one of the option
name = monthName(12);
function name = monthName(num)
name = month(datetime(1,num,1), 'name');
name = name{1};
end
Result:
name =
'December'

Prodotti

Release

R2020a

Richiesto:

il 23 Apr 2020

Modificato:

Rik
il 23 Apr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by