Tuesday, 15 May 2012
On 15:13 by Unknown in matlab tutorial 1 comment
Matlab Basic Part 2
In the first Part We See Some Basic of Matlab. now in the Part 2we will see some advanced functions and methods of Matlab. then we go forward to our work on the Telecom And Networking side. In this section we will see about the loop statements and how to draw plots figure etc.
if, if else, else Statement in Matlab
>> A=109;
>> B=104;
>> If (A > B)
>> fprintf('A is Greater than B');
>> elseif (A < B)
>> fprintf('B is greater than A');
>> elseif (A = = B)
>> fprintf('B is equal with A');
>> else
>> fprintf('Unexpected situation');
>> end
In Matlab, loops can be implemented with a for ...end construct or a while ...end construct. In terms of their ability to repeat a series of calculations, for loops and while loops are equivalent.
for Loops
for loops are often used when a sequence of operations is to be performed a predetermined number of times. For example computing the Maximum or Minimum of a list of numbers.
Syntax
Loop counter incremented by one:
for i = startingValue : endingValue
x = Some Value
y = Some value
Do somthing
...
...
...
end
Exp1: Compute the sum of the fi rst n integers
>> n = 10;
>> sum = 0;
>> for i = 1 : n
>> sum = sum + i;
>> end
Exp2: Compute the average of a list of numbers
>> n = 500;
>> x = rand(1,n); % generate a row vector of pseudo random number having length n
>> sum = 0;
>> for i=1:n
>> sum = sum + x(i); % Add ith element of x to sum
>> end
>> avg = sum/n;
while loop
While Loop is same as for loop, only the difference is it first check the condition then do action. syntax is below
while(condition)
...
...
do something
...
...
end
Switch Statement
In Matlab switch statement is same as other languages like C/C++. but in Matlab no parenthesis are used. the syntax is below:
switch(y)
case(1)
do something
break
case (2)
do something
break
...
...
...
case(n)
do something
break
default
display default message/ do default work
end
Graphics
Graphics are used to see the graphical representation of a sequence/ signal etc. In Matlab two major types of plot are used. one is "plot" command used for continuous signal, second is "stem" command for discrete type signal.
"subplot" command is used if one want to display multipull plots in one figure at different location. if one wants to display one plot together with another plot the after first plot "hold on" command is used. Remember that "figure" command is used to create one figure.
Exp 3: sine generation: A*sin(omega*n+theta)
>> n = 0: 1: 50;
>> A = 0.87; % Amplitude of sin wave
>> theta = 0.4; % Phase of sin wave
>> omega = 2*pi / 20; % frequency of sin wave
>> xn1 = A*sin(omega*n+theta); % sin generation
>> figure (1); % create first figure
>> subplot(2,1,1); % there are two locations for plot in figure 1
>> plot(xn1);
>> title('first signal');
>> xn2 = A.^n; % exp generation
>> subplot(2,1,2); % xn2 will be plot on the 2nd row 1st column
>> plot(xn2);
>> title('Exponential signal');
>> figure (2);
>> plot(xn1);
>> hold on;
>> plot(xn2);
>> hold off;
>> figure (3);
>> stem (n, xn1);
Subscribe to:
Post Comments (Atom)
Search
Popular Posts
-
Erlang B table is attached in this post with up to 115 number of channels, and more GOS probability values. This will help you to solve Erl...
-
Here in this post I discuss about how to connect MATLAB? And taking images from Webcam? So first of all we need a videobject of the web...
-
Erlang C table is attached in this post with up to 45 number of channels, and more GOS probability values. This will help you to solve Erla...
-
Mini Advanced Encryption Standard (Mini-AES): A Testbed for Cryptanalysis Students Raphael Chung-Wei Phan ADDRESS: Swin...
-
Programming Methodologies Two popular approaches to programming design are the structured approach and the object-oriented approach, whi...
-
Example Mini-AES Encryption The application of the four components NibbleSub , ShiftRow , MixColumn and KeyAddition in sequence con...
-
Telecommunication & Networking is the emerging technologies now a days. In fast these both fields are distinguish from each other. Tel...
-
Solution of DATA & Network Security Mid Term Paper Data & Network Security. ...
-
Matlab Basic Part 2 In the first Part We See Some Basic of Matlab. now in the Part 2we will see some advanced functions and methods of...
-
Basic to MATLAB Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environmen...
Categories
- Advanced Wireless Networks (26)
- Wireless Networks (21)
- Data and Network Security (20)
- Digital Logic Design (7)
- matlab tutorial (5)
- C Programing (3)
- Research Papers (2)
Editorial
- Javed Chaudhry (21)
- PANAMA Leaks (18)
- Wasat Ullah Khan (11)
- Abdul Qadir Hassan (10)
- PAK-America Relationship (7)
- Ali Ahmad Dhalo (6)
- Muqtada Mansoor (6)
- Asghar Abdullah (4)
- Dr. Abdul Qadeer Khan (4)
- PAK-India Relationship (4)
- Aftab Iqbal (2)
- Ayaz Ameer (2)
- Doctor Atta Ur Rehman (2)
- PAK-Afghan Relationship (2)
- PAK-Chaina Relationship (2)
- PAK-Iran Relationship (2)
- Anees Baqir (1)
Sample Text
Blog Archive
My Traffic
Powered by Blogger.
check it out for your help. if not contain info you need then write your problem in comments. you will be entertained, In Shah Allah
ReplyDelete