how to develop an application in scilab 2018-02-20 to develop... · 2019-01-11 · 1 how to develop...

Post on 22-Mar-2020

8 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

HowtodevelopanapplicationinScilab2018-02-20ByYannDebray–ESIGroup

ThisworkislicensedunderaCreativeCommonsAttribution-ShareAlike3.0UnportedLicense.

2 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

WelcometoScilab!Hereisafirstviewofyourdevelopmentenvironment.

FilebrowserOntheleftsideofthescreen,youwillfindthefilebrower.First,enterinthefolder/dev

3 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

Openthescriptregr.scebydoubleclickingonit:

Scinotes–integratededitorOpenthescriptinScinotes

4 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

YoucanattachtheScinoteswindowtoyourdefaultScilabenvironmentbydraganddropingtheblackribbononthetopofthewindow:

Thisisthescriptregr.sce:[FileName,PathName,FilterIndex] = uigetfile("*.csv"); if FilterIndex == 0 then messagebox("No file selected", "Error", "error", "modal"); return end A = csvRead(fullfile(PathName, FileName)); function regr(A) scf(); pressure = A(:,12); //Extract pressure component of the matrice A t = 1:length(pressure); [a,b] = reglin(t,pressure');//Linear regression on the pressure plot(pressure); plot(a*t+b,"r"); endfunction regr(A) Byclickingtheplaybutton,yourunthescriptregr.sce(youcanalsodothatwithoutopeningthefileinscinotes,byrightclickingthefileinthefilemanager).

5 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

Importdata

ThefirstlineopensawindowswiththefunctionuigetfileByselectingthecsvfilesensor-data.csv,itreturnsthecompletepathofthatfile:PathName = /Users/yanndebray/Google Drive/Scilab Knowledge Base/Demos/wea ther_desktop_app/dev ItcanthenbegivenasinputtothefunctioncsvRead,thatreadscommasperatedvaluesinScilabA = csvRead(fullfile(PathName, FileName));

Variablebrowser&editorItcreatesavariableAinourvariablebrowser:

6 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

Double-clickingonthevariableAwillopenitinaspreadsheetviewcalledthevariableeditor:

Byselectingthe12thcolumnofourmatrixA,wearedoingthesameaswritingintheconsole-->A(:,12)Wecanplottheresultwiththeiconinthemenu,orbytypinginyourconsole:-->plot2d(A(:,12))

7 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

WritingfunctionsThefollowingfunctiontakesasinputamatriceA,selectthe12thcolumn,computesthelinearregressiononthedataandplotit:function regr(A) scf(); pressure = A(:,12); //Extract pressure component of the matrice A t = 1:length(pressure); [a,b] = reglin(t,pressure');//Linear regression on the pressure plot(pressure); plot(a*t+b,"r"); endfunction Oncedefine,youcancallthefunctionasfollowed:regr(A) Itwillreturnthefollowinggraph:

8 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

DevelopaGraphicalUserInterfaceOpenthescriptinterface.sce:f = createWindow(); f.axes_size = [230 180]; f.figure_name = "My Interface"; uicontrol(f, ... "style", "pushbutton", ... "string", "Call my script", ... "position", [50 75 130 40], ... "callback", "regr"); Thisproducesthefollowingwindow:

9 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

Byclickingonthebutton“CallmyScript”,itcallsthefunctionregrdefinedearlier,andproducesonceagaintheplotofthelinearregressiononthepressuredata.(pleasenotethatyouwillneedtoexecutethescriptregr.scebefore,otherwise,thefunctionregrwillnotbefoundandwillreturnanerrorinyourconsole).InScilab,thedevelopmentofgraphicaluserinterfacescanbeentirelyperformedwithonemainfunction,uicontrol:h = uicontrol(PropertyName,PropertyValue,...)

Inthenexttutorial,wewillteachyouhowtodevelopthefollowingapplicationforweatherforecast:

ReadmoreonhowtodevelopGUIswithScilab:http://scilab.io/how-to-develop-a-graphical-user-interface-tutorial/

ThisworkislicensedunderaCreativeCommonsAttribution-ShareAlike3.0UnportedLicense.

top related