<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Rafael,<br>
    I had a hard but successful time to understand the approach. Almost
    magic!<br>
    Here is the complete executable snippet:<br>
    <pre style="font-family:Courier New;font-style:normal;font-size:12.0;"><span style="color:rgb(0,0,0);">   M</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Jan</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Feb</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Mar</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Apr</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188
,143,143);">May</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Jun</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Jul</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Aug</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Sep</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Oct</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);
">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Nov</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Dec</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(0,0,0);">;</span>
   <span style="color:rgb(0,0,0);">n</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">size</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">M</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
   <span style="color:rgb(0,0,0);">Ms</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Dec</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Apr</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">;</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Feb</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Dec</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">;</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Jun</span><span style="color:rgb(188,143,143);">'</span><span 
style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">Jul</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(0,0,0);">;</span> 
   <span style="color:rgb(50,185,185);">execstr</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">M</span> <span style="color:rgb(92,92,92);">+</span> <span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">=</span><span style="color:rgb(188,143,143);">'</span> <span style="color:rgb(92,92,92);">+</span> <span style="color:rgb(50,185,185);">string</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(255,170,0);">:</span><span style="color:rgb(0,0,0);">n</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(100,174,100);font-style:italic;">//equivalent to Jan=1., Feb=2., ..., Dec=12.   M remains unchanged</span>
   <span style="color:rgb(174,92,176);text-decoration:underline;">evstr</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">Ms</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(100,174,100);font-style:italic;">//matrix of numbers</span></pre>
    <br>
    Regards<br>
    Jens<br>
    -----------------------------------------------------<br>
    <div class="moz-cite-prefix">Am 20.10.2016 19:08, schrieb Rafael
      Guerra:<br>
    </div>
    <blockquote
cite="mid:DB5PR04MB1575659FE660DE208284E8F5CCD50@DB5PR04MB1575.eurprd04.prod.outlook.com"
      type="cite">
      <pre wrap="">Hi Scilaber's,

Fyi, another approach using execstr + evstr functions:

// use month names in M to create 12 variables that are assigned to some 12 numbers
-->execstr(M + '=' + string(1:size(M,2)));   
-->evstr(Ms)
 ans  =
    12.    4.   
    2.     12.  
    6.     7.  

This different approach will be much slower than using grep for very large input matrices.
However, it is worth knowing about it because execstr is one of the most powerful Scilab functions (see for instance the Meta programming chapter in: “Programming in Scilab”, by Michael Baudin, September 2011).

Regards,
Rafael

From: users [<a class="moz-txt-link-freetext" href="mailto:users-bounces@lists.scilab.org">mailto:users-bounces@lists.scilab.org</a>] On Behalf Of Mike Page
Sent: Thursday, October 20, 2016 1:32 PM
To: Users mailing list for Scilab <a class="moz-txt-link-rfc2396E" href="mailto:users@lists.scilab.org"><users@lists.scilab.org></a>
Subject: Re: [Scilab-users] Converting string months to month numbers

Hi Jens,
grep does something like what you want.

-->[r,w]=grep(Ms,M);
-->matrix(w,size(Ms))
 ans  =
 
    12.    4.   
    2.     12.  
    6.     7.   
 
Not sure why grep produces a vector when searching for a matrix, but it seems that way.
HTH,
Mike.

On 20 October 2016 at 10:32, Jens Simon Strom <a class="moz-txt-link-rfc2396E" href="mailto:j.s.strom@hslmg.de"><mailto:j.s.strom@hslmg.de></a> wrote:
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?

Backward (given Mn) it is easier to me:
Ms=matrix(M(Mn),size(Mn))

Regards
Jens



_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>