convert date/time input(in a array cell) as a serial day number array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

convert date/time input(in a array cell) as a serial day number array

LucaLuca
hi,

look this:

i've array cell

  [84,1] = 01-Apr-2018
  [85,1] =Nan
  [86,1] =Nan
  [87,1] =Nan
  [88,1] = 01-Ago-2018
  [89,1] =Nan
  [90,1] =Nan

i try to convert it in serial day number array

datenum (string_dat_rp)

but i receive this error:

error: datevec: none of the standard formats match the DATE string





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: convert date/time input(in a array cell) as a serial day number array

siko1056
On Wed, Jul 18, 2018 at 6:41 AM LucaLuca <[hidden email]> wrote:
hi,

look this:

i've array cell

  [84,1] = 01-Apr-2018
  [85,1] =Nan
  [86,1] =Nan
  [87,1] =Nan
  [88,1] = 01-Ago-2018
  [89,1] =Nan
  [90,1] =Nan

i try to convert it in serial day number array

datenum (string_dat_rp)

but i receive this error:

error: datevec: none of the standard formats match the DATE string



The problem is clear:

>> datenum ("Nan")
error: datevec: none of the standard formats match the DATE string 

What do you expect the output to be in this case?

Kai


Reply | Threaded
Open this post in threaded view
|

Re: convert date/time input(in a array cell) as a serial day number array

siko1056
>>> On Wed, Jul 18, 2018 at 6:41 AM LucaLuca <[hidden email]> wrote:
>>>
>>> hi,
>>> 
>>> look this:
>>> 
>>> i've array cell
>>> 
>>>   [84,1] = 01-Apr-2018
>>>   [85,1] =Nan
>>>   [86,1] =Nan
>>>   [87,1] =Nan
>>>   [88,1] = 01-Ago-2018
>>>   [89,1] =Nan
>>>   [90,1] =Nan
>>> 
>>> i try to convert it in serial day number array
>>> 
>>> datenum (string_dat_rp)
>>> 
>>> but i receive this error:
>>> 
>>> error: datevec: none of the standard formats match the DATE string
>>> 
>> Il Mercoledì 18 Luglio 2018 13:08, Kai Torben Ohlhus <[hidden email]> ha scritto: 
>> 
>> The problem is clear:
>> 
>> >> datenum ("Nan")
>> error: datevec: none of the standard formats match the DATE string 
>> 
>> What do you expect the output to be in this case?
>> 
>> Kai
>> 
> On Wed, Jul 18, 2018 at 1:25 PM luca salardi <[hidden email]> wrote:
> hi, kai

> i expect this:

>   [84,1] = 77778987
>   [85,1] =Nan
>   [86,1] =Nan
>   [87,1] =Nan
>   [88,1] = 77778983
>   [89,1] =Nan
>   [90,1] =Nan 


Please make sure, to keep the mailing list in the CC, that others may benefit from this question and we use bottom posting [1] for the emails, even many clients do not support this by default.

Okay, then you have to make sure, that datenum does not have to process the invalid string "Nan"

string_dat_rp = {"01-Apr-2018", "Nan", "Nan", "Nan", "01-Aug-2018", "Nan", "Nan"};
my_nans = cellfun (@(x) isequal (x, "Nan"), string_dat_rp);
string_dat_rp(my_nans)  = nan;
string_dat_rp(~my_nans) = num2cell (cellfun (@datenum, (string_dat_rp(~my_nans))));
disp (string_dat_rp)

{
  [1,1] =  737151
  [1,2] =  NaN
  [1,3] =  NaN
  [1,4] =  NaN
  [1,5] =  737273
  [1,6] =  NaN
  [1,7] =  NaN
}

My values are a bit different (used "Aug" instead of Italian "Ago") but I think the point is clear.

HTH,
Kai