How to convert number to string vector
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Danny
el 25 de Oct. de 2014
Comentada: Danny
el 25 de Oct. de 2014
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 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 25 de Oct. de 2014
Editada: Azzi Abdelmalek
el 25 de Oct. de 2014
a = [2014;2014];
b = [10;11];
c = [25; 24];
x=[a b c zeros(numel(a),3) ]
out=datestr(x,'yyyy_mmm_dd')
0 comentarios
Más respuestas (1)
dpb
el 25 de Oct. de 2014
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.
...
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!