Search code examples
scilab

Impossible to print a graph in scilab if I try it through a callback of a function because syslin doesn't consider both arguments to be equal


how are you, I'm making a GUI in scilab based on a tutorial of Openeering people, in the GUI that I'm making I need to plot the response of a system on the right side of the figure window. It prints an initial graph of the system and I've a button to print the new graph with the parameters set in some text boxes that the GUI has, so:

the code where I initially store the data written in the text boxes is

//Lista ordenada de valores por defecto
values1=[0.00074,0.3,8.7,0.48,3.9,0.0035];
//Posicionamiento
l1=30;l2=100;l3=110;
for k=1:size(labels1,2)
    uicontrol("parent",sistem_graf,"style","text","string",labels1(k),"position",[l1,guih1- 
    k*20+guih1o,l2,20],"horizontalalignment","left","fontsize",14,"background",[1 1 1]);
    guientry(k)=uicontrol("parent",sistem_graf,"style","edit","string",string(values1(k)),
    "position", 
    [l3,guih1k*20+guih1o,180,20],"horizontalalignment","left","fontsize",14,"background",
    [.9 .9 .9],"tag",labels1(k));
end

guientry(k) is the control that names the text boxes.

The button is generated with the following code

//Adicionando un botón
huibutton=uicontrol(sistem_graf,"style","pushbutton",...
"position",[110 100 100 20],"String","Graficar",...
"BackgroundColor",[.9 .9 .9], "fontsize",14,...
"Callback","Calcula_Sistema");

and the function that is the callback of the button which is called "Calcula_Sistema" is

function Calcula_Sistema()
    //Lee los parámetros del sistema
    parametros=[];  
    la=findobj("tag,""La [H]"); parametros.la=la;
    ra=findobj("tag","Ra [Ohm]"); parametros.ra=ra;
    in=findobj("tag","In [A]"); parametros.in=in;
    par=findobj("tag","Par [N*m]"); parametros.par=par;
    ke=findobj("tag","Ke [V/krpm]"); parametros.ke=ke;
    j=findobj("tag","j [N/m^2]"); parametros.j=j;

    //Lee los tiempos del sistema
    /*    Tsim=[];
    Tini=findobj("tag","Tinicio [s]"); Tsim.Tini=evstr(Tini);
    Tfin=findobj("tag","Tfin [s]"); Tsim.Tini=evstr(Tfin);
    Tpaso=findobj("tag", "Tpaso [s]"); Tsim.Tpaso=evstr(Tpaso);
    */    
    Sis_Motor(parametros.la,parametros.ra,parametros.in,
    parametros.par,parametros.ke,parametros.j); 
endfunction

when I press the button to generate the new graph the it gives me the error

at line 8 of function Sis_Motor ( F:\Users\valery\Documents\MEGAsync\UCV\Postgrado en Controles Industriales\Trabajo de Grado\Proyecto\Cálculos\Aplicación Scilab\Ventana.sce line 96 ) at line 18 of function Calcula_Sistema ( F:\Users\valery\Documents\MEGAsync\UCV\Postgrado en Controles Industriales\Trabajo de Grado\Proyecto\Cálculos\Aplicación Scilab\Ventana.sce line 142 )

syslin: Input arguments #2 y #3 incompatibles: Are expected of the same size.

The line 8 of the Sis_Motor function is the line 8 of the following code which is the Sis_Motor code

function [Wn,Zita,ftr,fta]=Sis_Motor(in,par,la,ra,ke,j)
    kt=par/in;
    n=kt/(j*la);
    b=j/10;
    d=[((b*ra+ke*kt)/(j*la)) ((b*la+j*ra)/(j*la)) 1];
    dpoly=poly(d,'s','c');
    t=[0:0.001:0.2];
    fta=syslin('c',n,dpoly);
    ftr=fta/(1+fta);
    [Wn,Zita]=damp(ftr);    
    graf=csim('step',t,ftr);
    delete(gca());
    plot2d(t,graf);
    legend('Respuesta al escalón');
    //Línea vertical.
    set(gca(),"auto_clear","off");
    graf_eje=gca();
    graf_eje.axes_bounds=[1/3,0,2/3,1];   
endfunction

I also tried changing the second line of Sis_Motor where is the following code

n=kt/(j*la);

for the line

n=[kt/(j*la) 0 0];      

but that didn't worked and the same errors keeps appearing.

I suppose that the error comes from the processing of the inputs of the text boxes but I don't know how to solve it

Can anyone help me with that?

Update 1:

findobj wasn't find the tags exactly as @Stephane Mottelet said, now is solved.


Solution

  • findobj yields a handle to the uicontrol. To recover the numeric value of edit boxes you have to write (here e.g. for ra)

    ra=findobj("tag","Ra [Ohm]"); parametros.ra=evstr(ra.string);
    

    If it still fails maybe the object is not found and findobj yields an empty matrix. Just insert disp(ra) after the findobj call to be sure that the tag is (or is not) found.