[Scilab-users] getting the name of a variable from its handle

sgougeon at free.fr sgougeon at free.fr
Tue Dec 6 20:36:23 CET 2016


Hello,

>----- Mail original -----
>De: "christophk"
>Envoyé: Mardi 6 Décembre 2016 14:43:25
>
>Ok here is another question for the Scilab experts around.
>Is there a way to convert the name of a variable into a string in Scilab?
>
>Lets say, I have:
>s = 2;
>
>//then:
>string(s) // returns "2"
>//is there a function f with f(s) == "s" ??

This is rather getting the variable name from the variable handle

AFAIK, this is possible only if s is the handle of a Scilab function (so called "macro"), i.e. a function written in Scilab language and compiled.

Example with the existing sind() function:
t = macr2tree(sind); t.name
// It works even with aliases:
s = sind;  // with no (): we copy the handle into s
s(45)
t = macr2tree(s); t.name

-->t = macr2tree(sind); t.name
 ans  =
 sind   
 
-->// It works even with aliases:
-->s = sind; // with no (): we copy the handle into s
-->s(45)
 ans  =
    0.7071068  
-->t = macr2tree(s); t.name
 ans  =
 s   

>Searched the web, but could only find a solution for Matlab:
>https://se.mathworks.com/matlabcentral/newsreader/view_thread/251347

I do not clearly understand what is done there. No results are displayed..
I don't know any equivalence of inputname() in Scilab.

HTH
Samuel Gougeon



More information about the users mailing list