Hi! We show you're using Internet Explorer 6. Unfortunately, IE6 is an older browser and everything at MindBites may not work for you. We recommend upgrading (for free) to the latest version of Internet Explorer from Microsoft or Firefox from Mozilla.

Click here to read more about IE6 and why it makes sense to upgrade.

Scilab: Functions and Using the Editor - Lesson 5

Preview

Like what you see? Buy now to watch it online or download.

You Might Also Like

About this Lesson

  • Type: Video Tutorial
  • Length: 4:29
  • Media: Video/mp4
  • Posted: 10/18/2009
  • Use: Watch Online & Download
  • Download: MP4 (iPod compatible)
  • Size: 14 MB

Scilab video tutorial lesson 5. Topics covered: functions, creating a function in Scilab, loading a function in Scilab, calling a function in Scilab. Introduction to the Scilab editor, using the editor to write Scilab programs.

Additional Materials

  • Once you purchase this lesson you will have access to these files:
  • UsingEditor_1.rtf UsingEditor_1.rtf
  • myFunctions.rtf myFunctions.rtf

Benefiting Charity

This lesson also donates 20% of author earnings to Any Baby Can: Any Baby Can

About this Author

Keith Schaub
Keith Schaub
18 lessons
Joined:
04/28/2009

Keith Schaub Founder of Wireless SOC Test Inc, author of the book, Production testing of RF and SOC devices for Wireless Communications, has over 14 years of experience in RF/microwave system design and test engineering. Additionally, he has authored/co-authored several papers and editorials on the state of RF/wireless SOC/SIP testing and the trends of the market including: "MIMO challenges existing ATE", Test & Measurement World, "Reducing EVM Test Time and Indentifying Failure Mechanisms", Evaluation Engineering, "Evolutionary Changes For RF Device Testing", Evaluation Engineering; "Needed: New Thinking For Wireless/RF Testing", Test and Measurement World, and "Concurrent-Parallel Testing...

More..

Recent Reviews

This lesson has not been reviewed.
Please purchase the lesson to review.

Recent Comments

This lesson has not been reviewed.
Please purchase the lesson to review.
Be the first to comment on this lesson!

Welcome to Lesson 5 Functions and Using the Editor. My name is Keith Schaub and I’ll be your host. In this lesson we’ll go over how to create, edit, save, and import functions using the integrated editor within Scilab.
Although you can write code directly in the console window, that is a very inefficient way to write programs and it is difficult to edit and save. Generally, you will want to start using the editor as soon as you can. It allows you to efficiently write, edit and save your programs and it has built-in key word recognition that color codes the text for you. This allows for quicker coding, since you can quickly spot errors, before you even attempt to run your program.
To begin, pull up the editor window by clicking on Applications and then Editor.
Let’s create a simple program that generates two arrays. A 64 point sine and a 64 point cosine and then let’s plot both of them.
Here is a 7 line program that does exactly what we want. Save this as “UsingEditor_1.sce”. To execute our program, you can either click Execute on the tool bar followed by Load into Scilab, or you can use the short-key “ctrl I’.
I’ve used the simplest plot command to display the two graphs. In a later lesson, we will discuss the myriad Scilab plotting capabilities. For now, just use the simple “plot”.
So, there you have it. We’ve created our first program using the editor.
Now, let’s build on this work and use the editor to create a function that computes the power of one of our signals. Once we have created the function, we’ll call the function from our newly created program and plot the frequency domain results.
Click file, new, to open a new editor. A function is defined by using the keyword “function” followed by the output parameters and the function name. Below that we write our function and then save the function as “myFunctions.sce”
Now, click Windows and change back to your program. At the top, let’s add two lines:
The first line changes the directory to where we saved our myFunctions.sce (your directory will be different).
The 2nd line uses the command (get function) getf followed by the function name. That’s all there is to it. Now, when we execute our program, it will read in our function.
We need to add a line to our program that calls the function and plots the results.

There you have it. We have successfully used the editor to create our first program. Additionally, we used the editor to create a function and then loaded and called that function from within our new program.
Now that you know the basics of how to use the editor and how to create and use functions, try creating a 2nd function that adds and subtracts the two arrays.
See you at the next lesson. Thanks, bye bye.

////////////// Function
function [powerdB]=calc_power_dB(x)
powerdB=20*log10((2/max(size(x)))*abs(fft(x)))

/////////// Program
cd 'C:\Documents and Settings\Keith Schaub\My Documents\SciLab\Tutorial_5';
getf myFunctions.sce

N=64; // Number of points
t=0:N-1; // array t = 1 to 63

// '//' indicates a comment
// anything after the // is ignored by Scilab

w=2*%pi;
// notice that "%pi" is purple indicating
// an internal variable to Scilab

x=cos(2*%pi*t/N);
y=sin(2*%pi*t/N);
// notice that 'cos' and 'sin' are blue indicating
// an internal Scilab function

plot(x);
plot(y);
// Scilab commands are indicated in green

power_dB=calc_power_dB(x); // Calls our new function

clf(); // clears any graphs
plot(power_dB); // Plots the results

Embed this video on your site

Copy and paste the following snippet: