Professional Documents
Culture Documents
Working With Data Files
Working With Data Files
Working With Data Files
’s
Nanasaheb Mahadik College of Engineering,
Peth
Nanasaheb Mahadik College of Engineering,
Peth
DEPARTMENT of
ELECTRICAL ENGINEERING
WELCOMES YOU
1
Department of Electrical
Engineering
Contents
Automating Commands with Scripts
Importing Data
Mixed Data Types
Cell Arrays
Exporting Data
2
Department of Electrical
Engineering
Command History
3
Department of Electrical
Engineering
Command History
3
Department of Electrical
Engineering
Editor Window and
Command Window
The Editor Window
Alternatively you can write a program or script called a m-file (has a .m
extension) in the Editor Window. The Editor Window is a word processor
specifically designed for Matlab commands so it automatically formats
certain things for you such as the command "for" below
The Command Window
Often times you will work at the command line in the command window.
The command window allows you to type commands directly and see the
results immediately. For example at the >>, define a variable "a" by typing
>> a=[1 2]
What is printed out below is the output of the command
a =
1 2
4
Department of Electrical
Engineering
Automating commands in MATLAB
scripts
3
Department of Electrical
Engineering
Creating Script Files
Steps
1.Go to Home Menu
2. select new script file
3.Open up Editor file
4.Write the program
5.Save the program and file name
6.Observe this in current folder
3
Department of Electrical
Engineering
Running script Files
Steps
1.Open editor file and write down the
program
2.Save program file
3.See this in the current folder
4.Run the program file or script
5.Observe the output in command window
6.See the output in command window
4
Department of Electrical
Engineering
Workspace Data
4
Department of Electrical
Engineering
Cell in MATLAB
4
Department of Electrical
Engineering
Cell in MATLAB
4
Department of Electrical
Engineering
Cell Mode Scripts
Cell mode is used to braking your scripts into different
sections.
To make independent operations
make a comment with % % at the starting of each section of
script
For Example
4
Department of Electrical
Engineering
Running cell mode scripts
Steps
1.Go to editor mode cell tool bar
2.Select Evaluate cell (ctrl + Enter)
3.You can run only one section at a time
4.Go to next section and press enter
5.Press ctrl + shift +enter to next section and
then evaluate cell and run that particular section
by selecting advanced button.
4
Department of Electrical
Engineering
Publishing of Scripts
16
Department of Electrical
Engineering
Basic plot options
For example let us plot the simple function y = x for
the range of values for x from 0 to 100, with an
increment of 5.
x = [0:5:100]; OUTPUT-
y = x;
plot(x, y)
16
Department of Electrical
Engineering
Basic plot options
16
Department of Electrical
Engineering
Basic plot options
For example
x = [0:0.01:10];
y = sin(x);
plot(x, y),
xlabel('x'),
ylabel('Sin(x)'),
title('Sin(x) Graph'),
grid on,
axis equal
16
Department of Electrical
Engineering
Basic plot options
16
Department of Electrical
Engineering
Annotating plots
16
Department of Electrical
Engineering
Annotating plots
annotation(lineType,x,y)
annotation(lineType,x,y) creates a line or arrow annotation
extending between two points in the current figure.
Specify lineType as 'line', 'arrow', 'doublearrow', or 'textarrow'.
Specify x and y as two-element vectors of the form [x_begin
x_end] and [y_begin y_end], respectively.
figure plot(1:10) x = [0.3 0.5]; y = [0.6 0.5];
annotation('textarrow',x,y,'String','y = x ')
16
Department of Electrical
Engineering
Annotating plots
annotation(lineType)
annotation(lineType) creates the annotation in the default
position between the points (0.3,0.3) and (0.4,0.4).
Create a simple line plot and add a text box annotation to the figure.
Specify the text description by setting the String property. Force the
box to fit tightly around the text by setting
the FitBoxToText property to 'on'.
figure plot(1:10) dim = [.2 .5 .3 .3]; str = 'Straight Line Plot from 1
to 10'; annotation('textbox',dim,'String',str,'FitBoxToText','on');
16
Department of Electrical
Engineering
Annotating plots
annotation(shapeType,dim)
annotation(shapeType,dim) creates a rectangle, ellipse, or text box
16
Department of Electrical
Engineering
Annotating plots
annotation(shapeType,dim)
annotation(shapeType) creates the annotation in the default
position so that the lower left corner is at (0.3,0.3) and the width
and height are both 0.1.
Create a stem plot and add a rectangle annotation to the figure.
Change the color of the rectangle outline by specifying
the Color property.
figure data = [2 4 6 7 8 7 5 2]; stem(data) dim = [.3 .68 .2 .2];
annotation('rectangle',dim,'Color','red')
16
Department of Electrical
Engineering