Posts

Showing posts from November, 2017

MATLAB / Octave Tutorial----Chapter 3-----Visualising the data(Part 3)

Image
Chapter 3: Visualising the data Part 3 Welcome to the third and the final part of this chapter. In this part, you'll come to learn how to plot complex(not in the mathematical sense!) functions. But before that, I shall show you some more tools about visualising the data. The first one is, subplot. This method is used for plotting different graphs on a single figure/window. The syntax for subplot is: subplot(a,b,c). Here, a is the number of rows in which the figure has to be divided into, b is the number of columns and c denotes the subdivision where we want to plot the graph. For example, subplot(2,1,1) means: Divide the graph into two rows and one column and plot the graph in the first subdivision. Fig 1: Demonstration of subplots We shall type the following on the command window and see the output. The output is shown below: Let's see a few more subplot examples: You can try various other variations of subplots. Howeve...

MATLAB / Octave Tutorial----Chapter 3-----Visualising the data(Part 2)

Image
Chapter 3: Visualising the data Part 2 Welcome to the second part of this chapter. In this chapter we will learn some more things about the plot function and also learn about a few more data visualizing functions.  One of the overloads of the plot function is : plot ( [x-data],[y-data],line-style/marker/color ) . Here, line color refers to a special string which denotes the color of the line in the graph. The following table denotes the colour coding scheme in MATLAB: Example : The following plot command prints a graph having red dotted lines: plot(x, y, ':r') Now, let us suppose that you need to plot another curve on the same graph, like, you want to plot the cubes of the numbers. Here's how you'll do it: Please note that, the function hold is used to retain the previous plot and allows us to plot more points on the same graph. hold on means the previous graph will be retained. Using hold off undoes the action. By default, t...

MATLAB / Octave Tutorial----Chapter 3----Visualising the data(Part 1)

Image
Chapter 3: Visualising the data Part 1 In this chapter, you'll come to know how to record your data and visualize it in the form of graphs. This chapter is of special importance as dealing with data is one of the prime aspects of MATLAB. However, before learning how to plot graphs, we must learn in detail, about the basic data structures of MATLAB, i.e., vectors and matrices. Vectors are one-dimensional arrays. It consists of space-separated or comma-separated elements. An example is shown below: Demonstration of vectors in MATLAB Matrices(singl.: matrix) are 2 dimensional arrays. It is declared as shown below: Demonstration of Matrix in MATLAB Each columns in a matrix is made using space separated or comma separated elements and each row is made using a semicolon. Like in the above example, A = [1 2; 3 4; 5 6]. The semicolon is placed after every two elements, with means, the first two elements are row 1, next two are row 2 and so on... Index...

MATLAB / Octave Tutorial-------Chapter 2------Arithmetic and Logical operations

Image
CHAPTER 2: Arithmetic and Logic Operations Using arithmetic and logic operations in MATLAB / Octave is easier than ever before. Its a very simple to use them and implement them in any operations. Just like any other computer language, the operators are same in MATLAB / Octave. For example:  Operator Function Example + Add a+b - Subtract a-b * Multiply a*b / Divide a/b ^ Exponent a^b & And a & b | Or a | b ! Not !a xor() Xor xor(a,b) The following shows how to use these operators: Demonstration of arithmetic operations Demonstration of Logical operators Before we begin with creation of MATLAB scripts, we must know two forms of data structures: vectors and matrices. Vectors are same as 1D arrays whereas matrices are 2D arrays. We declare vectors and ...

MATLAB / Octave tutorial-----Chapter 1------Constants and Variables

Image
CHAPTER 1: MATLAB / Octave basics At the very outset, let us see how the first opening window(also called terminal) of both the softwares look like: MATLAB opening window  Octave opening window If you look at both the windows you’ll see that all the toolbars are same, the interfaces are identical. So, let’s quickly learn a few commands and see the output from each. Please follow these steps: a)      Type the command on the prompt.   b)     Press enter. 1. clc: This command is used to clear the terminal screen. It is implemented like so:   Using 'clc' command From now onwards, we shall execute all commands in octave. All commands executed in octave runs exactly in the same way in MATLAB. All files in MATLAB and Octave are saved with the extension .m. 2.      Playing with constants: All numbers written on the prompt are echoed on th...