Introduction: How to Plot Sine Cosine Wave in MATLAB
In this tutorial you will learn how to PLOT SINUSOIDAL FUNCTIONS ( SINE COSINE ) in MATLAB
creating a script file that will make a set of data and plot that data. This is a very useful tool in all types of scientific and math based research allowing the user to take experimental data and look create a visual picture of things like position or velocity vs. time, or even fuel economy of a car over some distance.MATLAB by MathWorks is a computational tool used by many engineers, scientists, and mathematicians to analyse data and present their results in the form of numbers, images, or even video. The program uses matrix algorithms and a unique coding language that allow the user to work with massive systems of equations easily and efficiently. The program also has the power to do numerical evaluations when simple calculus can not be used. Just Follow these Instructions DONT FORGET TO FOLLOW ME ON INTRUCTABLE FOR FURTHER POSTS... A STEP BY STEP INSTRUCTION IS ALSO GIVEN IN THE BELOW VIDEO LINK .....
Step 1: Opening MATLAB PROGRAM
To complete this instructable you will need a computer, and the MATLAB software from MathWorks.This task should take between 5 and 10 min to be fully complete.
Step 2: Creating Script File
The easiest way to complete a task in MATLAB is to work in a script file. A script file is a secondary window that allows the user to edit and run a block of code all at one time completing several tasks simultaneously. To open a script file click on the button in the top left corner that says "New Script," (pictured above) for users with older versions of MATLAB this can be done by going to the file tab, selecting new then selecting script. Doing this opens a blank script file in a new window. Note that any commands given in the next several steps must be followed exactly. Any spelling, mis-capitalization, or missing lines will cause the code to crash, so please read the instructions carefully and type the code exactly as it is shown
Step 3: Clear Screen
When first starting a new script file it is important that you do not have any of the variables that are about to be used assigned to another task. In order to prevent this begin any script file with the following:
clear all This command clears any values that have been assigned to variables.Also for this particular script you may want to keep the command window on the main window clean. To do this enter the following on the next line your script file: clc The "clc" command wipes any previous work from the command window display.
Step 4: Write the CODE / Testing
Write the code in picture OR download the file given at the end .....
Click on the RUN Button Click on the ADD TO PATH if dialogue box is appear ..... Thats it IF YOU WANT TO UNDERSTAND MORE ABOUT THE CODING OF MATLAB VISIT THEIR WEBSITE..
Step 5: Code File
close all; clear all; t=0:0.01:10; a=7; f=0.5; y=a*cos(2*pi*f*t); subplot(2,1,1); plot(t,y); axis([-10 10 -10 10]); title('Cosine Function'); xlabel('Time Axis'); ylabel('Amplitude Axis'); y=a*sin(2*pi*f*t); subplot(2,1,2); plot(t,y); axis([-10 10 -10 10]); title('Sine Function'); xlabel('Time Axis'); ylabel('Amplitude Axis');