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 - scilab

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.

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.

Related

Decimal points to Hexadecimal Conversion in Verilog

I am working on a verilog code. I am completely new to verilog.
Suppose, I have to represent 0.6072529350088814 in hexadecimal, its value comes out to be 32'h26dd3b6a, as shown in code on the below :
https://electronics.stackexchange.com/questions/354594/cordic-algorithm-using-verilog
But I donot understand how this conversion works?
Suppose I want to display the value and see it in decimal, what should be code?
`timescale 1ns / 1ps
module top(
);
wire signed[31:0] init_value= 32'h26dd3b6a; // 0.6072529350088814
always#(*)
begin
$display("The init_value= %d", init_value);
end
endmodule
I have tested the above line of code, but this does not work.
The value of the init_value is displayed as
The init_value= 652032874
I expect that result should be 0.6072529350088814.
Code:
$display("The init_value = %f", $itor(init_value) / (2 ** 30));
Prints:
The init_value = 0.607253
I am not sure if the code under the link is correct. Theoretically, the conversion should be done through 2 ** 31 or 2 ** 32.

Scrapy can't manage to request text with neither CSS or xPath

I've been trying to extract some text for a while now, and while everything works fine, there is something I can't manage to get.
Take this website : https://duproprio.com/fr/montreal/pierrefonds-roxboro/condo-a-vendre/hab-305-5221-rue-riviera-854000
I want to get the texts from the class=listing-main-characteristics__number nodes (below the picture, the box with "2 chambres 1 salle de bain Aire habitable (s-sol exclu) 1,030 pi2 (95,69m2)", there are 3 elements with that class in the page ( "2", "1" and "1,030 pi² (95,69 m²)"). I've tried a bunch of options in XPath and CSS, but none has worked, some gave back strange answers.
For example, with :
response.xpath('//span[#class="listing-main-characteristics__number"]').getall()
I get :
['<span class="listing-main-characteristics\_\_number">\n 2\n </span>', '<span class="listing-main-characteristics\_\_number">\n 1\n </span>']
For example, something else that works just fine on the same webpage :
response.xpath('//div[#property="description"]/p/text()').getall()
If I get all the spans with this query :
response.css('span::text').getall()
I can find my texts mentioned in the beginning in the. But from this :
response.css('span[class=listing-main-characteristics__number]::text').getall()
I only get this
['\n 2\n ', '\n 1\n ']
Could someone clue me in with what kind of selection I would need? Thank you so much!
Here is the xpath that you have to use.
//div[#data-label='#description']//div[#class='listing-main-characteristics__label']|//div[#data-label='#description']//div[#class='listing-main-characteristics__item-dimensions']/span[2]
you might have to use the above xpath. (Add /text() is you want the associated text.)
response.xpath("//div[#data-label='#description']//div[#class='listing-main-characteristics__label']|//div[#data-label='#description']//div[#class='listing-main-characteristics__item-dimensions']/span[2]").getall()
Below is the python sample code
url = "https://duproprio.com/fr/montreal/pierrefonds-roxboro/condo-a-vendre/hab-305-5221-rue-riviera-854000#description"
driver.get(url)
# get the output elements then we will get the text from them
outputs = driver.find_elements_by_xpath("//div[#data-label='#description']//div[#class='listing-main-characteristics__label']|//div[#data-label='#description']//div[#class='listing-main-characteristics__item-dimensions']/span[2]")
for output in outputs:
# replace the new line character with space and trim the text
print(output.text.replace("\n", ' ').strip())
Output:
2 chambres
1 salle de bain
1,030 pi² (95,69 m²)
Screenshot:

How to increment value of a counter by clicking on a button?

I have a button like this :
win <- gwindow("Extraction des mots clés", visible=TRUE)
obj2 <- gbutton("Valider et afficher les mots suivants",container=win)
I want that each time I press the button, a counter which is set to 0 in my script is incremented.
k<-0
I created this handler :
addHandlerClicked(obj2,handler = function(h,...){
k<-k+1
print (k)
return(k)
})
but when I doprint k outside of the addHandlerClicked, kis still 0. So how can I do ? Moreover, is the instruction return (k)that I wrote above can be used to achieve this ?
Thanks in advance
This is the way R functions work. Objects in (global) workspace have one value and when you create a same-name object within a function, it has no memory of the same name object outside. R functions don't modify other variables, you have to return the modified value and overwrite it explictily. Normally. Enter <<-. This assignment operator will go from the function all the way to the global environment and try to find the same name object and write over/to it. See more info by typing ?"<<-".

Scilab plot with many lines: automatic cycling trough 'LineSpec' styles

I am plotting around 10 Lines in the same plot and use the built-in option of plot to cycle through colors. Sadly, this option only has 7 colors and then starts with the first color again. Is there an option like in Matlab to get a different line type, when the colors cycled through once?
I know I can change the color and line style manually for every line, but I would prefer an automatic solution.
I do not know a built-in way to do this, but reading the Linespec man page, you could create a function to cycle trough all specifiers.
The simplest of them being :
function Linespec=CycleSpec(n)
// n : from 0 to N
Linestyle =['-';'--';':';'-.']
Linecolor = ['r';'g';'b';'c';'m';'y';'k';'w']
Linemarker =['';'+';'o';'*';'.';'x';'s';'d';'^';'v';'>';'<';'p']
i = modulo(n,size(Linecolor,'*'))+1
j = modulo(floor(n/size(Linecolor,'*')),size(Linestyle,'*'))+1
k = modulo(floor(n/size(Linecolor,'*')/size(Linestyle,'*')),size(Linemarker,'*'))+1
Linespec = Linestyle(j)+Linecolor(i)+Linemarker(k)
endfunction
Which could be use as
figure(1)
for n=0:40
plot(x,x+n,CycleSpec(n))
end
And if you really want something simple, we can add a global variable storing the counter so you only need to call the function, no need for parameter
function Linespec=CycleSpec()
// n : from 0 to N
global CycleSpecCounter
if CycleSpecCounter==[] then
CycleSpecCounter = 0
end
n=CycleSpecCounter
[...] same code as before [...]
CycleSpecCounter=CycleSpecCounter+1
endfunction
and you'd only need to type
plot(x,x+n,CycleSpec())

dojox.grid.EnhancedGrid how do i set a noDataMessage?

I'm trying to set a noDataMessage into a dojox.grid.EnhancedGrid, the grid works fine, when the store get data it show it's row with no problem, but I need that when the store gets no data the grid would show me a personalized message. I set the noDataMessage property which is a string, but nothing happened when has no data.
How can I trigger the event when no data in the store?
I get my data through a SQL query to a database and the answer is JSON serialized data.
here's the code of my grid.
intersGrid = new dojox.grid.EnhancedGrid({
// plugins: {dnd: true},viewInterconsulta
id :"intersGrid",
store: interfiltStore,
structure: intersLayout,
noDataMessage:"<span class=\"dojoxGridNoData\">No hay Datos</span>",
loadingMessage:'Cargando datos. Por favor espere.',
//noDataMessage: 'No existen pacientes esta agenda.',
errorMessage:'No existen datos para esta busqueda.'
}, "intersDiv");
solved.
What you have to do is.
if you get an empty store then set them like these:
$filas = "{ identifier: 'ID', items[]}";
**json_encode($filas)."}";
and then dojo shows the noDataMessage
In my case, I only showed 25 rows and then requested with help of offset & count another 25 when scrolling down the list. In this case, I needed "numRows" - which is the total amount of rows, leaving out offset & count. The "numRows" was set to 0 if no rows where found. But if it was given, the noDataMessage was not shown (btw: An "identifier" is not required).
Also there is a syntax error in your json, add some ":" after "items".
This is the JSON for the store, which shows the noDataMessage of a dojox datagrid:
{"items":[]}
This will not show it:
{"items":[],"numRows":"0"}
Using Dojo 1.6.1, a dojox.grid.DataGrid with a dojox.data.QueryReadStore

Resources