Mtlab CMD

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Pwd path for working dir mkdir learn to create new dir from which ans will show.

w. Who which variables we have used whos how variable are used? Clear all it will clear all variables clc clear screen close all close all screens GUI clear all clear all varialbles & screens help elfun gives details to functions like round,near , etc help lang help for do-while , for loop

------------------------------------------------------------File new name file close all clear all clc # write new file

then store this file as demo.m

.m known as script .mat known as data file .fag figure

now start to write equation for simple pendulum

L = 1 ; % in meteres (comment can write after %) g = 10 ; k = 0;

theta0 = 15*pi/180 % initial angle in rad

Tfinal = 6 ; N = Tfinal/h ;

to add matrix : X = [1 2 3] Y = [1 2 3; 4 5 6; 7 8 9] X = X' # gives transpose of matrix X.*y = #matrix multiplication to array multiplication (need same dimension) to make any element change Y(2,3) = 0 # element in 2nd row & 3rd colomn will change to 0 to change full row Y(3,:) = 0 # changes all elements of 3rd row to 0

to change 2 & 3 row to 1 Y(2:3,:) = 1

to make 1st coloumn to 0 Y(1:end,1) = 0 # y starting from 1st element to end from 1st coloumn

to move selected matrix M = Y(1:2,2:3) # 1st row to 2nd row & 2nd coloumn to 3rd column

auto fill vector v=1:10 # create v = 1 2 3 4 .10 u=0:0.1:1 #

a=[1 2 3]; # create to matrix a but not use in out , it stores it for use

plot a graph

xAxis =[0:2*pi]; yAxis=[sin(xAxis)] plot(yAxis)

--- ---

plot(xAxis,yAxis) # plots x axis against y axis

to add label : xlabel('Angle(radian)') ylabel('amplitude') title('sinusoidal')

---- --------------------------------------------to change angle from radian to degree xDegree=90/pi*xAxis; plot(xDegree,yAxis)

--- ------------------------------------------------to draw signal real against time

You might also like