A blog to help electrical engineers and students to learn electrical engineering topics. Basic Electrical Engineering, Power Systems, Electrical Machines, tec.. Now special course on MATLAB for Beginners.

Class

Class

Monday, December 26, 2016

User Defined Functions in MATLAB Part -2



Previous post we discussed what is a user defined function in MATLAB. This lecture we will discuss how to define a function and how to call the function in a script. Components of a function is discussed in the previous lecture. The first statement in a function must be function definition.The basic syntax of a function definition is: function[a, b, c]= basicmath(x,y) Basically a function accepts an input vector, perform the operation,...

Thursday, December 1, 2016

User Defined Functions in MATLAB - Part 1



User-defined functions are similar to the MATLAB predefined functions. A function is a MATLAB program that can accept inputs and produce outputs. A function can be called or executed by another program or function. Code for a function is done in an Editor window or any text editor same way as script and saved as m-file. The m-file must have the same name as the function. It is important that you give meaningful variable names to variables inside...

Tuesday, November 22, 2016

MATLAB Programming - Loop Control Part 2



In this lecture we will discuss more about Loop control. - Switch – case commands - Nested lops - break command - continue command switch - case Command There is no conditional statement used in this looping structure. It choose the code to be executed based on value of scalar or string, not just true/false. Different codes can be executed based on the value of the scalar defined in the switch command. The codes are defined using...

Wednesday, October 26, 2016

MATLAB Script - Loop Control Part 1



In this lecture we will discuss about another flow control method – Loop control. A loop control is used to execute a set of commands repeatedly The set of commands is called the body of the loop. MATLAB has two loop control techniques  Counted loops - executes commands a specified number of times.  Conditional loops - executes commands as long as a specified expression is true. The counted loops are called ‘for’ loop and the...

Conditional Control in MATLAB Scripts with Examples



In this lecture we discuss more about programming in MATLAB. One main section in programming is flow control. There are many flow control commands in MATLAB. In this lecture we discuss the conditional flow control commands. Conditional statements are commands that allows MATLAB to decide whether or not to execute some code that follows the statement Conditional statements use relational operators like ==,~=,>,< (Note that are all scalar...

Wednesday, September 21, 2016

MATLAB Scripts - Examples with Electrical Engineering Applications



› This lecture we will practice some Basic MATLAB Scripts. ›We will start with simple scripts and will discuss some electrical engineering applications. Program to calculate Electricity bill. w = input('Enter power of your device (in watts): '); h = input('Enter time (in hours): '); r = input('Enter electricity rate (in dollars per KWH): '); ec = w * h/1000 * r; disp(’Your Electricity bill is’) Disp(ec) Power transfer vs Load...

Saturday, September 10, 2016

Introduction to MATLAB Scripts



MATLAB Script or programs are sequences of MATLAB commands saved in plain text files. When you type the name of the script file at the MATLAB prompt the commands in the script file are executed as if you had typed them in command window. Code for a script is done in an Editor window and saved as m-file.  In case your code has errors, MATLAB will show an error message in the command window, when you try to run the program . Error message...

Sunday, September 4, 2016

MATLAB Programming Tips 2 - Input and Output Commands



In this lecture we will review some common input and output commands in MATLAB. These commands are discussed in detail in previous lectures. For detailed Lectures on Input and Output commands follow the links below. Basic data Input Commands Basic Display and Output Commands MATLAB programming tips 2 - Input and Output Commands from Shameer Ahmed Koya...

Sunday, August 28, 2016

MATLAB Programming Tips Part 1



MATLAB program (functions and scripts) are stored as script file(.m files). This type of file contains MATLAB commands, so running it is equivalent to typing all the commands—one at a time—at the Command window prompt. You can run the file by typing its name at the Command window. Matlab Programming Tips Part 1 from Shameer Ahmed Koya Both functions and scripts are stored in .m files —Type up a bunch of commands and save as filename.m —Type...

Tuesday, August 23, 2016

Polynomials and Curve Fitting in MATLAB



MATLAB provides a number of functions for the manipulation of polynomials. Polynomials are defined in MATLAB as row vectors made up of the coefficients of the polynomial, whose dimension is n+1, n being the degree of the polynomial. Polynomials in MATLAB vector must include all polynomial coefficients, even those that are zero. MATLAB provides the function polyval to evaluate polynomials. MATLAB does not provide a direct function for adding or...

Friday, August 5, 2016

Working with Excel files in MATLAB - Part 2



Read part 1 here. We will discuss few more functions to deal with Excel files. xlswrite ( ) – Write to Microsoft Excel spreadsheet file xlswrite is a simple function to write data to an excel worksheet. The syntax is similar to the xlsread function xlswrtie(‘filename’, A, ‘worksheet’, ‘range’) The function write the values in the array A to the specified range of cells in the specified worksheet of the excel file. The array may be a numeric...

Friday, July 22, 2016

Working with Excel files in MATLAB - Part 1



MATLAB have many builtin functions to work with Excel files. In this post, we will discuss some of the common functions to work with Excel files.  It is easy to interact with an excel file using xlswrite and xlsread commands. First we will make an sample excel file test.xlsx which contain grades of students in a class. xlsread ( ) - Read Microsoft Excel spreadsheet file The xlsread function reads data from the first worksheet of a Microsoft...

Friday, July 15, 2016

Working with Text files in MATLAB - Part 2



In part one we discussed about basic functions to deal with text files. Now we will discuss more function to read from and write to different types of text files. csvwrite( )  - Write comma-separated value file csvwrite is the basic function in MATLAB to write data to a file as comma-separated values. It has only limited options to write numeric data to the file. The syntax is: csvwrite(filename, C) The function writes matrix C into the...

Saturday, July 2, 2016

Working with Text files in MATLAB - Part 1



MATLAB can import text files both interactively and programmatically. Import Tool used to import data interactively. The Import Tool supports text files, including those with the extensions .txt, .dat, .csv, .asc, .tab, and .dlm. Data in these files can be a combination of numeric and nonnumeric text, and can be delimited by one or more characters. There are many inbuilt functions to import and export data from and to the text files programmatically....