Replace obsolete function "str2code"

Hello,
I have to replace the obsolete function “str2code”, but it doesn’t work.

Here is the old version:
KR=str2code(part(Scherung(7,2),2:3));

And then I tried this:
KR=ascii(part(Scherung(7,2),2:3));

But this line will create an index-error message:
if KR(2,1)==40 then …

Any idea? Many thanks.

Hello,

Can you show the content of

part(Scherung(7,2),2:3)

please ? I guess this is just a problem of vector shape, i.e. you are expecting a column vector but ascii() yields the transpose. So you should just rewrite your test so that the actual shape (row or column vector) does not matter, i.e.

if KR(2)==40 then

S.

1 Like

Hello mottelet, “Scherung” is an Excel-Worksheet, and the content of "Scherung(7,2) is a string of two chars, in this example the string “A1”.

OK, that’s what I said

--> ascii(part("A1",2:3))
 ans  =

   49.   32.

so a column vector, so use adequate matrix index (1,2) or generic vector index (2)

S.

1 Like

Hello Stefan,

I’m not sure what do you want to do with “A1” but if the goal is to convert it to [i,j] form like “A1” => [1,1], “Z64” => [64, 26]

I write something some years ago (updated version):

function ret = excel2scilab(cell)
    ret = [];
    b = [1 26];

    cell = convstr(cell, "u");
    [_, _, _, d] = regexp(cell, "/([A-Z]+)([0-9]+)/");

    a = ascii(d(1)) - ascii("A") + 1;
    c = sum(a($:-1:1) .* b(1:size(a, "*")));

    ret = [strtod(d(2)) c];
endfunction
excel2scilab("A4")
 ans  =
   4.   1.

excel2scilab("AT521")
 ans  =
   521.   46.

excel2scilab("TA46")
 ans  =
   46.   521.
1 Like