フィルターのクリア

How to convert number to string vector

6 ビュー (過去 30 日間)
Danny
Danny 2014 年 10 月 25 日
コメント済み: Danny 2014 年 10 月 25 日
I have three vectors representing years, months, and days:
a = [2014;2014];
b = [10;11];
c = [25; 24];
and at the very least I want to put them in a string vector such as:
Vector = ['2014_10_25' ; '2014_11_24']
I am unsure how to do this conversion. The best case would be an output of:
Vector = ['2014_Oct_25' ; '2014_Nov_24']
but my goal is to convert the year, month, and day numerical vectors into one string vector.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 25 日
編集済み: Azzi Abdelmalek 2014 年 10 月 25 日
a = [2014;2014];
b = [10;11];
c = [25; 24];
x=[a b c zeros(numel(a),3) ]
out=datestr(x,'yyyy_mmm_dd')

その他の回答 (1 件)

dpb
dpb 2014 年 10 月 25 日
Trivial...
>> [a,b,c]
ans =
2014 10 25
2014 11 24
>> datestr(datenum(a,b,c)) % default format
ans =
25-Oct-2014
24-Nov-2014
>> datestr(datenum(a,b,c),'yyyy-mmm-dd') % your requested format
ans =
2014-Oct-25
2014-Nov-24
>>
See
doc datenum % and friends for details
As hint on how to find these things while learning Matlab,
>> lookfor date % returns in part
collectdata - Given cell array of nx3 per cell of date, stockID, return as
doc_datacursormode - Plots graph and sets up a custom data tip update function
myadddate - ADDDATE - version vectorized...
sunny - Given cell array of nx3 per cell of date, stockID, return as
dateTickPicker - Returns ticks for "best" scale.
datetickstr - Returns the date string associated with the values input. Any values of
invalidateaxis - Invalidate an axis to recompute limits and ticks
convertSpreadsheetDates - Convert cells in a spreadsheet to MATLAB datenum format
...
addtodate - Add a quantity to a date field.
clock - Current date and time as date vector.
date - Current date as date string.
datenum - Serial date number.
datestr - String representation of date.
datetick - Date formatted tick labels.
datevec - Date components.
now - Current date and time as date number.
...
  1 件のコメント
Danny
Danny 2014 年 10 月 25 日
Thank you for the very helpful answer

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by