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

9
1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20 By Yann Debray – ESI Group This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Upload: others

Post on 22-Mar-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

1 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

HowtodevelopanapplicationinScilab2018-02-20ByYannDebray–ESIGroup

ThisworkislicensedunderaCreativeCommonsAttribution-ShareAlike3.0UnportedLicense.

Page 2: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

2 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

WelcometoScilab!Hereisafirstviewofyourdevelopmentenvironment.

FilebrowserOntheleftsideofthescreen,youwillfindthefilebrower.First,enterinthefolder/dev

Page 3: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

3 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

Openthescriptregr.scebydoubleclickingonit:

Scinotes–integratededitorOpenthescriptinScinotes

Page 4: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

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).

Page 5: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

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:

Page 6: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

6 HOWTODEVELOPANAPPLICATIONINSCILAB|Tutorial

Double-clickingonthevariableAwillopenitinaspreadsheetviewcalledthevariableeditor:

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

Page 7: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

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:

Page 8: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

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:

Page 9: How to develop an application in Scilab 2018-02-20 to develop... · 2019-01-11 · 1 HOW TO DEVELOP AN APPLICATION IN SCILAB | Tutorial How to develop an application in Scilab 2018-02-20

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.