Creation of variable and graphical handles programmatically

classic Classic list List threaded Threaded
3 messages Options
Sébastien Bihorel-2 Sébastien Bihorel-2
Reply | Threaded
Open this post in threaded view
|

Creation of variable and graphical handles programmatically

Dear Scilab users,

I wonder how one can create variables or graphical handles programmatically and assign values to them at the same time. For instance, consider the following attempted code where nstates 'sub-plots' should be created within a figure (please, note that I don't want to use the subplot function for some other reason). This syntax is obviously wrong, according to the Scilab error message, but I do not know how to fix that. Any help would be greatly appreciated.

Sebastien


///////////////////
figure()

nstates=6;
ndim= ceil(sqrt(nstates));
multi=pmodulo((1:nstates)-1,ndim);
margin=0.05;

for (j=1:nstates)
    eval('g' + string(j) + '=newaxes()')
    eval('g' + string(j) + '.axes_bounds=[' + string(multi/ndim) + ',' +...
          string(marg + multi*(1-marg)/ndim) + ',' +...
          string(1/dim) + ',' +...
          string((1-marg)/ndim) + ']');
end

/////////////// Scilab error message
%h=g1=newaxes();
       !      
at line       3 of function %eval                    called by : 
line    17 of function eval                     called by : 
eval('g' + string(j) + '=newaxes();')
Pierre LANDO Pierre LANDO
Reply | Threaded
Open this post in threaded view
|

Re: Creation of variable and graphical handles programmatically

Try something like that : execstr instead of eval


figure();

nstates=6;
ndim= ceil(sqrt(nstates));
multi=pmodulo((1:nstates)-1,ndim);
marg=0.05;

for (j=1:nstates)
    execstr('g' + string(j) + '=newaxes()');
    execstr('g' + string(j) + '.axes_bounds=[' + string(multi/ndim) +
',' +...
          string(marg + multi*(1-marg)/ndim) + ',' +...
          string(1/ndim) + ',' +...
          string((1-marg)/ndim) + ']');
end



Sébastien Bihorel a écrit :
> Dear Scilab users,
>
> I wonder how one can create variables or graphical handles
> programmatically and assign values to them at the same time. For
> instance, consider the following attempted code where nstates
> 'sub-plots' should be created within a figure (please, note that I
> don't want to use the subplot function for some other reason). This
> syntax is obviously wrong, according to the Scilab error message, but
> I do not know how to fix that. Any help would be greatly appreciated.


--
-------------------------
Pierre LANDO
Ingénieur de développement
-------------------------
Consortium Scilab
Digiteo
Domaine de Voluceau
Rocquencourt - B.P. 105
78153 Le Chesnay Cedex France
Tél. : +33.1.39.63.58.21


Sébastien Bihorel-2 Sébastien Bihorel-2
Reply | Threaded
Open this post in threaded view
|

Re: Creation of variable and graphical handles programmatically

It's working great. Thank you very much !

On Mon, Oct 12, 2009 at 7:46 AM, Pierre LANDO <[hidden email]> wrote:
Try something like that : execstr instead of eval



figure();

nstates=6;
ndim= ceil(sqrt(nstates));
multi=pmodulo((1:nstates)-1,ndim);
marg=0.05;

for (j=1:nstates)
  execstr('g' + string(j) + '=newaxes()');
  execstr('g' + string(j) + '.axes_bounds=[' + string(multi/ndim) + ',' +...

        string(marg + multi*(1-marg)/ndim) + ',' +...
        string(1/ndim) + ',' +...

        string((1-marg)/ndim) + ']');
end



Sébastien Bihorel a écrit :

Dear Scilab users,

I wonder how one can create variables or graphical handles programmatically and assign values to them at the same time. For instance, consider the following attempted code where nstates 'sub-plots' should be created within a figure (please, note that I don't want to use the subplot function for some other reason). This syntax is obviously wrong, according to the Scilab error message, but I do not know how to fix that. Any help would be greatly appreciated.


--
-------------------------
Pierre LANDO
Ingénieur de développement
-------------------------
Consortium Scilab
Digiteo
Domaine de Voluceau
Rocquencourt - B.P. 105 78153 Le Chesnay Cedex France
Tél. : +33.1.39.63.58.21