summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayan Bhawal2018-09-27 09:45:14 +0530
committerChayan Bhawal2018-09-27 09:45:14 +0530
commit5f24e94950f3d3f059cb266309cb5b07b7ecdb32 (patch)
tree5e327bde32c371abe68850ae77af138ed4b950b0
parentad60e147f47b699b3d4953a1901e3c2742013e59 (diff)
downloadscilab-tutorials-5f24e94950f3d3f059cb266309cb5b07b7ecdb32.tar.gz
scilab-tutorials-5f24e94950f3d3f059cb266309cb5b07b7ecdb32.tar.bz2
scilab-tutorials-5f24e94950f3d3f059cb266309cb5b07b7ecdb32.zip
Tutorial1_functions_filehandling
-rw-r--r--Tutorial1/Data/.~lock.Tut1_data2.csv#1
-rw-r--r--Tutorial1/Data/Tut1_data1.csv16
-rw-r--r--Tutorial1/Data/Tut1_data2.csv15
-rw-r--r--Tutorial1/Scilab_code/Tutorial1_function.sce27
-rw-r--r--Tutorial1/Scilab_code/Tutotial1_input_files.sci24
-rw-r--r--Tutorial1/Scilab_code/mymean.sci9
-rw-r--r--Tutorial1/Scilab_code/mystdev.sci8
7 files changed, 100 insertions, 0 deletions
diff --git a/Tutorial1/Data/.~lock.Tut1_data2.csv# b/Tutorial1/Data/.~lock.Tut1_data2.csv#
new file mode 100644
index 0000000..9856f47
--- /dev/null
+++ b/Tutorial1/Data/.~lock.Tut1_data2.csv#
@@ -0,0 +1 @@
+,chayan,Serendipity,27.09.2018 09:41,file:///home/chayan/.config/libreoffice/4; \ No newline at end of file
diff --git a/Tutorial1/Data/Tut1_data1.csv b/Tutorial1/Data/Tut1_data1.csv
new file mode 100644
index 0000000..472523d
--- /dev/null
+++ b/Tutorial1/Data/Tut1_data1.csv
@@ -0,0 +1,16 @@
+0.05077,0.0038966667
+0.02751,0.00365
+0.02075,0.0036866667
+0.01881,0.0037333333
+0.01938,0.0037933333
+0.08237,0.00385
+0.03718,0.0038766667
+0.03714,0.0041033333
+0.03657,0.0039433333
+0.0362,0.00392
+0.048,0.0040733333
+0.04172,0.0040966667
+0.04115,0.0042166667
+0.0435,0.00409
+0.04202,0.0362
+0.0487,0.04172
diff --git a/Tutorial1/Data/Tut1_data2.csv b/Tutorial1/Data/Tut1_data2.csv
new file mode 100644
index 0000000..4b99c91
--- /dev/null
+++ b/Tutorial1/Data/Tut1_data2.csv
@@ -0,0 +1,15 @@
+order,time1,time2,time3,time4
+2,7.33333333333333E-05,0,3.33333333333333E-06,0.0038966667
+3,2.33333333333333E-05,0,3.33333333333333E-06,0.00365
+4,0.00003,0,6.66666666666667E-06,0.0036866667
+5,3.33333333333333E-05,0,3.33333333333333E-06,0.0037333333
+6,3.33333333333333E-05,0,3.33333333333333E-06,0.0037933333
+7,0.00004,0,3.33333333333333E-06,0.00385
+8,0.00004,3.33333333333333E-06,0.00001,0.0038766667
+9,0.00005,3.33333333333333E-06,3.33333333333333E-06,0.0041033333
+10,4.66666666666667E-05,0.00001,6.66666666666667E-06,0.0039433333
+11,0.00004,3.33333333333333E-06,6.66666666666667E-06,0.00392
+12,0.00005,0.00001,0.00001,0.0040733333
+13,5.66666666666667E-05,0.00001,0.00001,0.0040966667
+14,6.33333333333333E-05,6.66666666666667E-06,1.66666666666667E-05,0.0042166667
+15,5.66666666666667E-05,6.66666666666667E-06,0.00001,0.00409
diff --git a/Tutorial1/Scilab_code/Tutorial1_function.sce b/Tutorial1/Scilab_code/Tutorial1_function.sce
new file mode 100644
index 0000000..164430c
--- /dev/null
+++ b/Tutorial1/Scilab_code/Tutorial1_function.sce
@@ -0,0 +1,27 @@
+//This Matlab script is used to compute mean and standard deviation of data
+
+//Clears all previous variables stored
+clear
+
+//Clears screen
+clc
+
+
+//Executing the mymean function that computes the mean of a given data
+exec mymean.sci;
+//Executing the mystdev function that computes the standard deviation of a given data
+exec mystdev.sci;
+
+
+//Data for which the mean and standard-deviation is required
+x = [1 2 5];
+
+//Calling the mymean function. It takes data (a vector) as the input argument and returns mean of the data as output
+mean_of_x = mymean(x);
+disp(mean_of_x,'Mean of x');
+
+//Calling the mystdev function. It takes data (a vector) and its mean as the input argument
+//It returns standard deviation of the data as output
+stddev_of_x = mystdev(x,mean_of_x);
+disp(stddev_of_x,'Standard deviation of x');
+
diff --git a/Tutorial1/Scilab_code/Tutotial1_input_files.sci b/Tutorial1/Scilab_code/Tutotial1_input_files.sci
new file mode 100644
index 0000000..da9279a
--- /dev/null
+++ b/Tutorial1/Scilab_code/Tutotial1_input_files.sci
@@ -0,0 +1,24 @@
+//This function is to import data from a csv file and store it in a variable
+//Using the data mean and standard deviation of the data is computed
+clear
+clc
+
+exec mymean.sci;
+exec mystdev.sci;
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial1/Data/Tut1_data1.csv');
+x = Data(:,1);
+y = Data(:,2);
+
+
+//Compute mean of the imported data
+mean_of_Data_x = mymean(x);
+
+//Compute standard deviation of the imported data
+standard_deviation_of_Data_x= mystdev(x,mean_of_Data_x);
+
+
+//Display mean and standard deviation in command window
+disp(mean_of_Data_x,'Mean of x',standard_deviation_of_Data_x,'Standard deviation of x')
+
diff --git a/Tutorial1/Scilab_code/mymean.sci b/Tutorial1/Scilab_code/mymean.sci
new file mode 100644
index 0000000..6a96da4
--- /dev/null
+++ b/Tutorial1/Scilab_code/mymean.sci
@@ -0,0 +1,9 @@
+//Function to compute mean of a given data (a vector)
+
+function mean_of_data = mymean(data)
+ sum_of_data = 0;
+ for iteration = 1:1:length(data)
+ sum_of_data = data(iteration) + sum_of_data;
+ end
+ mean_of_data = sum_of_data/length(data);
+endfunction
diff --git a/Tutorial1/Scilab_code/mystdev.sci b/Tutorial1/Scilab_code/mystdev.sci
new file mode 100644
index 0000000..53849a4
--- /dev/null
+++ b/Tutorial1/Scilab_code/mystdev.sci
@@ -0,0 +1,8 @@
+//A function to compute standard deviation of a given data
+//Input: Data (a vector) and mean of the data as input
+//Output: standard deviation of the data
+
+function standard_dev = mystdev(data,mean_of_data)
+ temp = (data - mean_of_data*ones(length(data)))^2;
+ standard_dev = sqrt(sum(temp)/(length(data)-1));
+endfunction