Is it possible to change a double with exonents so no exp or decimal?

조회 수: 1 (최근 30일)
I am trying to change dates in cells in the form [19861001010000] (yyyy mm dd hh mmmm) to a number that I can parse into the year, month, etc. I used G = [cellfun(@str2num,Date(:,1))]; because I had a column of cell dates after using textscan to import data. This gave me a column of numbers in exponential notation (eg. 1.9861e+13). In order to parse this number I need this column to be whole numbers, I think (eg. 19861001010000). And then I plan to extract the year, month etc. to make a graph. Any advice about how I should approach this?

채택된 답변

Shaun VanWeelden
Shaun VanWeelden 2013년 4월 19일
OK, I would absolutely leave it as a string until it is finished parsing!
The 1.9861e+13 still represents all values by the way, but that doesn't matter in this approach.
I would just do something like str='19861001010000'
year=str(1:4);year=str2double(year);
OR more compact
month=str2double(str(5:6));
the idea being you simply convert one portion of your date at a time to a double value.
Instead of making 6 variables, you can also do date(1)=year; date(2)=month, etc. or just do:
date=[ str2double(str(1:4)) str2double(str(5:6)) etc.. ];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by