# How to develop an application in Scilab

Welcome to Scilab! Here is a first view of your development environment. File browser

On the left side of the screen, you will find the file brower.

First, enter in the folder /dev Open the script regr.sce by double clicking on it: Scinotes – integrated editor

Open the script in Scinotes You can attach the Scinotes window to your default Scilab environment by drag and droping the black ribbon on the top of the window : This is the script regr.sce:

```[FileName,PathName,FilterIndex] = uigetfile("*.csv");

if FilterIndex == 0 then

messagebox("No file selected", "Error", "error", "modal");

return

end

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

By clicking the play button, you run the script regr.sce (you can also do that without opening the file in scinotes, by right clicking the file in the file manager).

Import data The first line opens a windows with the function uigetfile

By selecting the csv file sensor-data.csv, it returns the complete path of that file:

```PathName  =

ther_desktop_app/dev   ```

It can then be given as input to the function csvRead, that reads comma sperated values in Scilab

`A = csvRead(fullfile(PathName, FileName)); `

Variable browser & editor

It creates a variable A in our variable browser: Double-clicking on the variable A will open it in a spreadsheet view called the variable editor: By selecting the 12th column of our matrix A, we are doing the same as writing in the console

`--> A(:,12)`

We can plot the result with the icon in the menu, or by typing in your console:

`--> plot2d(A(:,12))` Writing functions

The following function takes as input a matrice A, select the 12th column, computes the linear regression on the data and plot it :

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

Once define, you can call the function as followed:

`regr(A)`

It will return the following graph: Develop a Graphical User Interface

Open the script interface.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");`

This produces the following window: By clicking on the button “Call my Script”, it calls the function regr defined earlier, and produces once again the plot of the linear regression on the pressure data. (please note that you will need to execute the script regr.sce before, otherwise, the function regr will not be found and will return an error in your console).

In Scilab, the development of graphical user interfaces can be entirely performed with one main function, uicontrol:

`h = uicontrol(PropertyName,PropertyValue,...)`

In the next tutorial, we will teach you how to develop the following application for weather forecast: Read more on how to develop GUIs with Scilab.
{"ft_lang_label":"__label__en","ft_lang_prob":0.75213426,"math_prob":0.77270436,"size":3361,"snap":"2023-40-2023-50","text_gpt3_token_len":822,"char_repetition_ratio":0.12511171,"word_repetition_ratio":0.09001957,"special_character_ratio":0.24427254,"punctuation_ratio":0.17664671,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9878662,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28],"im_url_duplicate_count":[null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-11-29T06:42:37Z\",\"WARC-Record-ID\":\"<urn:uuid:27eeba34-8bb8-4bfc-8e6d-aabb7d605642>\",\"Content-Length\":\"32820\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:94921b6a-1beb-4152-8a27-87c60dd1bf5e>\",\"WARC-Concurrent-To\":\"<urn:uuid:54910729-2c19-4ace-8612-76da6ccaa88f>\",\"WARC-IP-Address\":\"107.154.79.223\",\"WARC-Target-URI\":\"https://www.scilab.org/how-to-develop-an-application-in-scilab\",\"WARC-Payload-Digest\":\"sha1:ESCFBEQMP2TICW67MIPK6SJEKWUWYMVW\",\"WARC-Block-Digest\":\"sha1:MUAKG3I3NNIHBDETNQYJTI43PWLL7USF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100056.38_warc_CC-MAIN-20231129041834-20231129071834-00770.warc.gz\"}"}