フィルターのクリア

Using values in an array to represent characters?

2 ビュー (過去 30 日間)
Noah Kebschull
Noah Kebschull 2017 年 11 月 26 日
回答済み: KL 2017 年 11 月 26 日
I have a vector x= [1:1:12]. Each value, from 1 to 12, should represent the corresponding months January to December. 1 is equal to January, 2 is equal to February, and so on. How would I do this, if possible? Also, if I were to create a new vector by selecting values from vector x, how would I display only the corresponding months. For example, my vector is M = [1 2 4 5 6] and I want it to display the months that correspond with those values.

採用された回答

KL
KL 2017 年 11 月 26 日
Use datetime to generate a vector of datetimes and then use month property,
dt = datetime([2017*ones(12,1) (1:12).' ones(12,1)]);
month_names = month(dt,'name');
now month_names has all your month names,
12×1 cell array
'January'
'February'
'March'
'April'
'May'
'June'
'July'
'August'
'September'
'October'
'November'
'December'
Extract it just by indexing,
res = month_names([1 2 4 5 6])
res =
5×1 cell array
'January'
'February'
'April'
'May'
'June'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by