Re: [Scilab-users] global constant definition for module
Le 04/03/2016 23:33, Samuel Gougeon a écrit : Le 02/03/2016 12:24, David Chèze a écrit : Hi all, I would like to define a variable in a user module in such a way that this constant would be available for all functions (also out of the module) as a "hidden(you don't need to see it inbrowsvar), protected (should not be possible to clear it, even with clearglobal )" global variable as soon the module is loaded: do you have suggestions how to do it within scilab? There is still no actual solution to protect variables against clear. . Actually, there are one or two solutions : 1. Set and store your constants in a TCL session (the main one or a slave), and recall them from it. Data in TCL sessions are not cleared by clear() nor by clearglobal(). This is what i use in drivers published on the fileexchange to set/get "persistent" communication parameters with devices. 2. May be the same could be possible with java objects? I have never tried. 3. Another solution is to use the userdata field of the default figure. The default figure (gdf()) is not clearable. But then all your graphic windows will embed your constants in their .userdata. So it is preferable not to have MBytes of constantes ;) And to set a struct() in userdata. This is a rather bad hacking. May be there are other solutions. Let's free your imagination :) Samuel ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Le 04/03/2016 23:33, Samuel Gougeon a écrit : .../... // In your scilab.ini/.scilab : load(path_to_set_constantes_sci+"/lib") // Where you need constantes: set_constantes() // Then use the constantes defined in set_constantes() The main advantage with this is that you don't need to remember where set_constantes.sci is stored (to exec() it). The other advantage is that, contrarily to with "global", we don't need to list the names of variables to be set as global. This list is defined inside set_constantes(). It becomes implicit from outside. SG ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Le 02/03/2016 12:24, David Chèze a écrit : Hi all, I would like to define a variable in a user module in such a way that this constant would be available for all functions (also out of the module) as a "hidden(you don't need to see it inbrowsvar), protected (should not be possible to clear it, even with clearglobal )" global variable as soon the module is loaded: do you have suggestions how to do it within scilab? There is still no actual solution to protect variables against clear. But you may do the following: // Save that in set_constantes.sci and build a library with it, thanks to genlib(), say constantes_lib function set_constantes() L0 = ""; L0 = who("local") c0 = 299792458 avog = 6.022045e23 planck = 6.626176e-34 qproton = 1.6022e-19 L0 = setdiff(who("local"), L0) execstr("["+strcat(L0,",")+"] = resume("+strcat(L0,",")+")") endfunction // In your scilab.ini/.scilab : load(path_to_set_constantes_sci+"/lib") // Where you need constantes: set_constantes() // Then use the constantes defined in set_constantes() The main advantage with this is that you don't need to remember where set_constantes.sci is stored (to exec() it). But nothing is protected: neither the library, nor set_constantes(), nor the constantes it defines. --> clear avog --> set_constantes() --> avog avog = 6.022D+23 HTH Samuel ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Le 03/03/2016 10:03, David Chèze a écrit : Hi Serge, thanks for this solution. I've just run your example on scilab 6 beta 1 and it fails complaining about undefined variable A. then I ran the example for lib function in scilab help and it fails equally : it looks like it is broken then I will report a bug on this unless already done. The example of the lib() help page is completely outdated. We could update and improve the page whether lib() keeps any interest wrt load(), or not. IMO, it would be preferable to upgrade load() -- mainly to make it able to return the list of names of loaded variables --, and undocument lib(), as written earlier in this thread. Regards Samuel ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] Plot w. part of background in a different color
Hello Clauss, Here is an example that you may customize: x = linspace(0,10,100); clf drawlater plot(x,sin(x)) xgrid(color("grey70")) xfpolys([2 5 5 2 ; 7 8.5 8.5 7]',[-1 -1 1 1; -1 -1 1 1]',.. [color("scilabpink") color("bisque")]) r = gca(); r.grid_position = "foreground"; r = r.children(1).children; r.line_mode="off"; r(1).data(:,3)=-1; r(2).data(:,3)=-1; drawnow HTH Samuel Le 04/03/2016 21:54, Claus Futtrup a écrit : Hi there A friend of mine uses Python matplotlib for some graphs and I'd like to generate similar graphs in Scilab. I've attached an example of such a plot. What I'd like to replicate is part of the background shaded in green and red. I think the function in Python matplotlib is something like: axvspan (xmin,xmax,ymin=0,ymax=1,hold=None, **kwargs) The kwargs are named arguments, for example: facecolor='g',alpha=0.1 Examples here: http://matplotlib.org/examples/pylab_examples/axhspan_demo.html http://physicalmodelingwithpython.blogspot.no/2015/08/function-arguments-args-and-kwargs.html How would I do similar stuff in Scilab? (Searching for vspan and hspan didn't give any hits). Best regards, Claus ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
[Scilab-users] Plot w. part of background in a different color
Hi there A friend of mine uses Python matplotlib for some graphs and I'd like to generate similar graphs in Scilab. I've attached an example of such a plot. What I'd like to replicate is part of the background shaded in green and red. I think the function in Python matplotlib is something like: axvspan (xmin,xmax,ymin=0,ymax=1,hold=None, **kwargs) The kwargs are named arguments, for example: facecolor='g',alpha=0.1 Examples here: http://matplotlib.org/examples/pylab_examples/axhspan_demo.html http://physicalmodelingwithpython.blogspot.no/2015/08/function-arguments-args-and-kwargs.html How would I do similar stuff in Scilab? (Searching for vspan and hspan didn't give any hits). Best regards, Claus ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] Matrix: mix string and float
Hello, >De: "anna78" 4 Mars 2016 14:45:10 >.../... >Is it possible to build a matrix with different element types? This is called a cell array. In your case, since each column is homogeneous, you may as well store the 13 matrices simply in a list: M = list(M1,M2,..,M13). The most appropriate container -- cell array or list -- depends on which kind of operations you wish to do afterwards with M's components. HTH Samuel Gougeon ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] Matrix: mix string and float
example M1=(1:15)';M2="foo"+string(M1);M3=sin(M1/10); M=tlist("cblock",M1,M2,M3) M(1:2,:) M(:,1) //the result is a standard array of numbers M(:,2) //the result is a standard array of strings This kind of data structure can be obtained directly reading a data file with mfscanf with the attached file u=mopen("foo1") M=mfscanf(-1,u,"%d %s %f\n") mclose(u) One can also use the cell array M=cell(1,3); M.entries(1)=M1; M.entries(2)=M2; M.entries(3)=M3; This solution will be more simple under Scilab 6 M1=(1:15)';M2="foo"+string(M1);M3=sin(M1/10); M={M1,M2,M3} M{:,1}//the result is a standard array of numbers Le 04/03/2016 14:45, anna78 a écrit : dear all, I have 13 column vectors: M1, M2, M13. One is an integer /%d) vector, two are string (%s) vectors, the others are double (%f). I would like to build the matrix M=[M1 M2 M3... M13], but it looks like not working. Is it possible to build a matrix with different element types? thanks Anna -- View this message in context: http://mailinglists.scilab.org/Matrix-mix-string-and-float-tp4033620.html Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com. ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users 1 a 0.2 2 b -0.5 3 c 33 ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
[Scilab-users] Matrix: mix string and float
dear all, I have 13 column vectors: M1, M2, M13. One is an integer /%d) vector, two are string (%s) vectors, the others are double (%f). I would like to build the matrix M=[M1 M2 M3... M13], but it looks like not working. Is it possible to build a matrix with different element types? thanks Anna -- View this message in context: http://mailinglists.scilab.org/Matrix-mix-string-and-float-tp4033620.html Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com. ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users