[Scilab-users] Converting string months to month numbers

Samuel Gougeon sgougeon at free.fr
Fri Oct 21 19:24:51 CEST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161021/8128e7e0/attachment.htm>


More information about the users mailing list