<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Jens<br>
      <br>
      Thanks for sharing. :-)<br>
      <br>
      Best regards,<br>
      Claus<br>
      <br>
      On 21-10-2016 10:49, Jens Simon Strom wrote:<br>
    </div>
    <blockquote cite="mid:5809D68C.4020605@hslmg.de" type="cite">
      <meta content="text/html; charset=windows-1252"
        http-equiv="Content-Type">
      <pre wrap="">Hi Scilabers,
Rafael's approach motivated me to share the following function with you.
</pre>
      <br>
      <pre style="font-family:Courier New;font-style:normal;font-size:12.0;"><span style="color:rgb(176,24,19);">function</span> <span style="color:rgb(131,67,16);font-weight:bold;">y</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);text-decoration:underline;">findbystr</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">X</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">Y</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(100,174,100);font-style:italic;">//find Y(x) from Y(X), X and x beeing string matrices</span>
    <span style="color:rgb(100,174,100);font-style:italic;">//X: keys to Y, matrix of strings</span>
    <span style="color:rgb(100,174,100);font-style:italic;">//Y: values allocated to X, matrix of constants, number of rows and colums like X</span>
    <span style="color:rgb(100,174,100);font-style:italic;">//x: argument keys, matrix of strings which are elements of X</span>
    <span style="color:rgb(100,174,100);font-style:italic;">//y: values for x, matrix of constants, numbers of rows and colums like x</span>
    <span style="color:rgb(100,174,100);font-style:italic;">// findbystr() finds numerical values y by their string keys x.  The string number allocation is defined bei X and Y.</span>
  <span style="color:rgb(50,185,185);">execstr</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">X</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(131,67,16);font-weight:bold;">Y</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(74,85,219);">)</span>
  <span style="color:rgb(131,67,16);font-weight:bold;">y</span><span style="color:rgb(92,92,92);">=</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(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">)</span>  
<span style="color:rgb(176,24,19);">endfunction</span>

<span style="color:rgb(100,174,100);font-style:italic;">//Example</span>
<span style="color:rgb(0,0,0);">X</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);">a</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);">b</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);">c</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);">d</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(74,85,219);">]</span>
<span style="color:rgb(0,0,0);">Y</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span> <span style="color:rgb(188,143,143);">10</span><span style="color:rgb(0,0,0);">,</span>     <span style="color:rgb(188,143,143);">20</span><span style="color:rgb(0,0,0);">;</span>   <span style="color:rgb(188,143,143);">30</span><span style="color:rgb(0,0,0);">,</span>   <span style="color:rgb(188,143,143);">40</span><span style="color:rgb(74,85,219);">]</span>
<span style="color:rgb(0,0,0);">y</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);text-decoration:underline;">findbystr</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">d</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);">c</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);">b</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);">c</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);">b</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);">a</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);">X</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">Y</span><span style="color:rgb(74,85,219);">)</span></span></pre>
      <br>
      The function would have been useful to me in the past several
      times  -  and certainly in the future.<br>
      <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 moz-do-not-send="true" 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 moz-do-not-send="true" 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 moz-do-not-send="true" 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 moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
      </blockquote>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
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>
    <p><br>
    </p>
  </body>
</html>