str2double breaks when you pass in a vector?

4 Ansichten (letzte 30 Tage)
59morgan
59morgan am 28 Dez. 2016
Kommentiert: Walter Roberson am 28 Dez. 2016
this works:
double = str2double('06012015');
but this doesn't:
doubles = str2double(['06012015' '06022015']);
whos doubles gives me this:
-------
6.0120e+14
Name Size Bytes Class Attributes
doubles 1x1 8 double
-------
  1 Kommentar
Jan
Jan am 28 Dez. 2016
['06012015' '06022015'] is the same as '0601201506022015' .

Melden Sie sich an, um zu kommentieren.

Antworten (2)

KSSV
KSSV am 28 Dez. 2016
str1 = str2double([{'106012015'} {'06022015'}])
str2 = str2num(['06012015' ;'06022015'])
  2 Kommentare
59morgan
59morgan am 28 Dez. 2016
thanks for your help
what I really want to do is this:
%start with a date times vector
datetimes = [datetime('06/01/2015') ; datetime('06/02/2015')];
%now remove any kind of punctuation, we just want digits
date_strings = datestr(datetimes, 'mmddyyyy');
%now convert those char arrays to doubles? docs say you can pass in a char array vector...
doubles = str2double(date_strings);
%problem: the date strings get concatenated and it doesn't work
Walter Roberson
Walter Roberson am 28 Dez. 2016
str2double( cellstr(date_strings) )

Melden Sie sich an, um zu kommentieren.


Sean de Wolski
Sean de Wolski am 28 Dez. 2016
In >=R2016b, you can just call double on the string directly:
double(string({'06012015' '06022015'}))

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by