How to convert number to string vector
조회 수: 8 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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')
댓글 수: 0
추가 답변 (1개)
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.
...
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!