These are some basic MATLAB Commands.
Ctrl + c
|
stop any action in matlab
|
clc
|
clear screen
|
clear
|
to clear whole workspace (value of any variable in workspace)
|
clear y
|
clears variable y
|
save
|
save to the file
|
load
|
load the saved file
|
x=5;y=6;
|
using “;”, code can be written in one line
|
z=x+5;
|
this gives value of z as 10
|
x=5,y=6;
|
creates two variable
|
v=z*…
5
|
v=10*5=50 i.e. Three dots “…” helps to continue the command in anther
line.
|
help [command name]
i.e help format
|
It gives information about command format
|
format loose
|
gives one line space between each line
|
format compact
|
removes the spacing between lines
|
format long
|
gives answer with 15 digits decimal
|
figure
|
opens a blank window for plotting (say name is “figure 1”)
|
close(1)
|
close the “figure 1” window
|
close all
|
close all the opened windows
|
edit
|
to open editor
|
5/2
|
gives ans = 2.5
|
sym(5/2)
|
gives ans = 5/2
|
up arrow key
|
to pop up command history
|
Format bank
|
To remove scientific display
e.g. : 10e+3 will be displayed as 10000
|
1. Plotting in MATLAB
x=[1,2,3];
y=[5,6,4];
plot(x,y);
|
x and y are vectors and plot
function plots (1,5), (2,6), (3,4) showing the points in a line
|
Length(x)
|
it gives ans = 3 because in x vector there are there elements.
|
plot(x,y,‘*’)
|
plots points as ‘*’
|
plot(x,y,’rs’)
|
plots point with r= red color and s=square shape
|
Plot(x1,y1,x2,y2)
|
Plots two functions y1 and y2 on same graph
|
Legend(‘pt1’,’pt2’)
|
Index or legend for point1 and point2
|
grid on
|
shows gird on the plotted windows
|
xlabel(‘x-axis’)
|
shows x-axis as the label of X-axis
|
ylabel(‘x-axis’)
|
shows y-axis as the label of Y-axis
|
title(‘ploting points’)
|
shows plotting points as the title of the plot
|
axis([0,10,2,8])
|
min_X=0, max_X=10, min_Y=2, max_Y=8 i.e. they are axis limit
|
2. plotting BAR CHART
bar(x,y)
|
plots bar chart
|
|
|
3. Plotting PIE CHART
pie([2 4 7 8 7])
|
each vector elements separated by space give the size of piece of pie
chart
|
4. Displaying IMAGES IN
MATLAB
pic=imread(‘palace.jpg’);
image(pic)
|
pic is a variable. imread() is a function. palace.jpg is filename of
image located in the current folder. image() is a function which takes
variarble pic as argument.
|
5. Matrix
y(:,1)
|
If you define a bidimensional (2D) array y, and
you want to access all its elements on the first column
|
y(5,:)
|
If you want to access to all the elements of
the fifth row:
|
:
|
The colon means: take all the elements along
the specified dimension
|
5. integration
>> syms x
>> int(sin(x),x,1,5)
|
it will integrate sinx with respect to x from 1 to 5
|
6. Writing to .txt file
Fid = fopen(filename, ‘wt’)
fprintf(op, text_to_be_written_to_the_file);
fclose(op)
|
e.g. op=fopen(‘average.txt’, ‘wt’)
fprintf(op, ‘This text will be written to the file ’)
fclose(op)
|
Wt
|
Replaces the content of existing file
|
At
|
Adds the current content to the previously existing content of file
|
No comments:
Post a Comment