[Scilab-users] Converting string months to month numbers

Jens Simon Strom j.s.strom at hslmg.de
Fri Oct 21 22:35:56 CEST 2016


Hallo,
Knowing execstr(), evstr(), and grep() now I would leave them alone and 
use members().
Here is my example.

function  y=!keytovalue(x,X,Y)//extract values by key
    //X: key, matrix of constants or strings
    //Y: value, matrix, shape as X, not necessarily type
    //x: request key, matrix, containing elements of X  only
    //y: value at x,  matrix, shape as x, type as Y
    [nb,loc]  =  members(x,  X)
    y=matrix(Y(loc),size(x))  
endfunction

//Example
X=['a','c';  'b','d'];
Y=[  'aa',  'cc';'bb','dd'];
y=!keytovalue(['d','c','b';'c','b','a'],X,Y)


Regards
Jens
--------------------------------------------------------------------------------------------------------------------------------------------------

Am 21.10.2016 19:24, schrieb Samuel Gougeon:
> Le 20/10/2016 11:32, Jens Simon Strom a écrit :
>> Hallo,
>> Given the string vector
>>
>> M=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
>> which implicitly maps the string representation of the months to their number representataion I would like to map any string matrix containing elements of M into a numercal matrix showing the month numbers.
>> E. g.
>> Ms=['Dec','Apr';'Feb','Dec';'Jun','Jul']
>> should be converted to
>> Mn=[12,4;2,12;6,7].
>>
>> Ho can that be done in a vectorial style?
>
> .
> It is the members()'s job, that works whatever is the type of data 
> (not only texts):
> M   =  ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];  
> Ms  =  ['Dec','Apr';'Feb','Dec';'Jun','Jul'];
> [tmp,  Mn]  =  members(Ms,  M);  Mn
>
> --> M  = 
> ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; 
>
> --> Ms = ['Dec','Apr';'Feb','Dec';'Jun','Jul'];
> --> [tmp, Mn] = members(Ms, M); Mn
>  Mn  =
>    12.   4.
>    2.    12.
>    6.    7.
>
> HTH
> Samuel
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161021/f3c7addd/attachment.htm>


More information about the users mailing list