in this article i want to discuss the function size.
size function returns the size of the array.
observe the following code:
x=[1 2 3 4];
[m,n]=size(x);
disp(m);
disp(n);
the output of the above code is 1,4
here the size function gets the size of the array as 1*4 and it stores 1 in 'm' and 4 in 'n'.
Tuesday, November 16, 2010
Monday, November 15, 2010
MATLAB-6(FUNCTION FIND)
in this article i want to discuss the function 'find':
find returns the indices of an array elements which have non zero value
just see the following array:
[1 2 0 0 3]
in this the first,second,fifth elements have non zero value so the find function returns 1,2,5.
observe the following code:
x=[1 2 0 0 3];
y=find(x);
disp(y);
this code gives the output 1,2,5.
and observe the following code:
x=[1 2 0 0 3];
[y,z]=find(x);
disp(y);
disp(z);
this code gives the output as
1 1 1
1 2 5
[y,z]=find(x);
in this line find function gets the rows and columns numbers of the non zero elements of the array x.
observe the following code:
x=[1 2 0 0 3];
[y,z,v]=find(x);
disp(y);
disp(z);
disp(v);
in the above code
[y,z,v]=find(x);
gets the rows and columns numbers of the non zero elements of the array x and v contains the non zero array of x i.e here v contains 1 2 3.
so the output of the above code is
1 1 1
1 2 5
1 2 3
we can run the above code in the command window also with or with out using disp.
thats it!
find returns the indices of an array elements which have non zero value
just see the following array:
[1 2 0 0 3]
in this the first,second,fifth elements have non zero value so the find function returns 1,2,5.
observe the following code:
x=[1 2 0 0 3];
y=find(x);
disp(y);
this code gives the output 1,2,5.
and observe the following code:
x=[1 2 0 0 3];
[y,z]=find(x);
disp(y);
disp(z);
this code gives the output as
1 1 1
1 2 5
[y,z]=find(x);
in this line find function gets the rows and columns numbers of the non zero elements of the array x.
observe the following code:
x=[1 2 0 0 3];
[y,z,v]=find(x);
disp(y);
disp(z);
disp(v);
in the above code
[y,z,v]=find(x);
gets the rows and columns numbers of the non zero elements of the array x and v contains the non zero array of x i.e here v contains 1 2 3.
so the output of the above code is
1 1 1
1 2 5
1 2 3
we can run the above code in the command window also with or with out using disp.
thats it!
MATLAB-5(POLAR PLOTS )
yesterday i had studied radiation patterns of antennas and bhargav ! one of my friends just wants me to plot the radiation patterns in matlab...........and i can finally plot the radiation patterns.
to plot cos(pi/2 cos(theta).........i had written the following code:
theta=0:pi/40:2*pi
en=cos(pi/2.*cos(theta));
polar(theta,abs(en));
and i got the output as shown bellow:
in the above code plot function will not give correct result as it can plot linear graphs only.and here i got this plot only because of the function 'polar'.but the disadvantage is it cant plot negetive values.so to eliminate that one we should use the function 'abs'.
obseve the following code once:
theta=0:pi/40:2*pi;
en=cos(pi.*cos(theta));
polar(theta,abs(en));
this code is for cos(pi cos(theta))
and the output that i got is as shown above:
theta=0:pi/40:2*pi
en=cos(pi/2.*cos(theta)).*cos(pi.*cos(theta));
polar(theta,abs(en));
the output of the above code is as shown bellow:
Friday, November 12, 2010
MATLAB-4(LEGEND,HOLD ON)
in this article i want to discuss the following things.
1.legend
2.hold on
the function legend is used to describe the various graphs with some identification so that any one can understand what each graph is ment for.
observe the following code:
x=0:1:10;
y1=x.^2;
y2=x.^3;
plot(x,y1,x,y2);
legend('y=x^2','y=x^3');
observe the result of this code:
from the above graph we can observe that because of the legend function we r getting y=x^2 and y=x^3 on the top of the graph with colors.................
now lets discuss about 'hold on':
hold on fixes all the properties of axes remain so that we can plot the graphs in one window.observe the following code:
x=0:.1:10;
y1=x.^2;
y2=x.^3;
y=x;
plot(x,y1);
hold on;
plot(x,y2);
plot(x,y);
the result of this graph is;
from the above graph we can say that all the graphs are present in a single window..............and this is possible only because of the 'hold on'.thats it..................
1.legend
2.hold on
the function legend is used to describe the various graphs with some identification so that any one can understand what each graph is ment for.
observe the following code:
x=0:1:10;
y1=x.^2;
y2=x.^3;
plot(x,y1,x,y2);
legend('y=x^2','y=x^3');
observe the result of this code:
from the above graph we can observe that because of the legend function we r getting y=x^2 and y=x^3 on the top of the graph with colors.................
now lets discuss about 'hold on':
hold on fixes all the properties of axes remain so that we can plot the graphs in one window.observe the following code:
x=0:.1:10;
y1=x.^2;
y2=x.^3;
y=x;
plot(x,y1);
hold on;
plot(x,y2);
plot(x,y);
the result of this graph is;
from the above graph we can say that all the graphs are present in a single window..............and this is possible only because of the 'hold on'.thats it..................
Thursday, November 11, 2010
MATLAB-3
in this article i want to discuss about
1.plot
2.subplot
3.semilogy
4.clc
plot is a function that is used to plot graphs in matlab
x=1:10;
y=x.^2;
plot(x,y);
the above code gives y=x^2 graph........and we will discuss where to use the dot and where not to use the dot in another article.
and observe the following code for the discussion of subplot:
x=1:10;
y1=x.^2;
y2=x;
subplot(2,1,1);plot(x,y1);
subplot(2,1,2);plot(x,y2);
here the code 2,1,1 specifies that there are 2*1 number of figures(2 rows and 1 colomn)(first and second numbers of 2,1,1) among them the first figure(which is indicated by the third number) should be the first one.
observe that 2,1,2 specifies (the third number) it is the second figure among the 2*1 figures.the output for the above code is as shown bellow:
thats it......................
and lets discuss about semilogy:
semilogy(x,y);plots the y vs x graph..........but it takes y in db i.e log base 10 values and x on a linear scale.similarly semilogx plots the y vs x graph taking x values to log base 10.
observe the following code:
x =1:1:100;
semilogy(x,x);
and the output is as shown bellow:
now we can observe that the y is plotted as in db.........but it is shown with normal scale only.........however the values r taken by log scale.
now lets discuss about clc;
clc operation is nothing but Clear Command Window thats it.............
1.plot
2.subplot
3.semilogy
4.clc
plot is a function that is used to plot graphs in matlab
x=1:10;
y=x.^2;
plot(x,y);
the above code gives y=x^2 graph........and we will discuss where to use the dot and where not to use the dot in another article.
and observe the following code for the discussion of subplot:
x=1:10;
y1=x.^2;
y2=x;
subplot(2,1,1);plot(x,y1);
subplot(2,1,2);plot(x,y2);
here the code 2,1,1 specifies that there are 2*1 number of figures(2 rows and 1 colomn)(first and second numbers of 2,1,1) among them the first figure(which is indicated by the third number) should be the first one.
observe that 2,1,2 specifies (the third number) it is the second figure among the 2*1 figures.the output for the above code is as shown bellow:
thats it......................
and lets discuss about semilogy:
semilogy(x,y);plots the y vs x graph..........but it takes y in db i.e log base 10 values and x on a linear scale.similarly semilogx plots the y vs x graph taking x values to log base 10.
observe the following code:
x =1:1:100;
semilogy(x,x);
and the output is as shown bellow:
now we can observe that the y is plotted as in db.........but it is shown with normal scale only.........however the values r taken by log scale.
now lets discuss about clc;
clc operation is nothing but Clear Command Window thats it.............
Wednesday, November 10, 2010
CONTEMPORARY COMMUNICATIONS USING MATLAB BOOK DOWNLOAD
this helps to learn matlab in a good way.............download this book for better matlab performance..............to download this book CLICK HERE
MATLAB-2
in this article i want to discuss about how to write for loop and if statement.
the following code gives an idea about for loop...............and this code generates the numbers from 1 to 10.
for i=1:10
disp(i);
end
so from the code we can say every for loop should have an end statement.............that end statement is end.
the if statement uses some logical operators for decision making........they r
&-and
|-or
~-negation
observe the following code for if statement..........
a=input('enter the value of a');
b=input('enter the value of b');
if((a>1)&(b>1))
for i=1:10
disp(i);
end
end
the code gives the output as the number from 1 to 10 if and only if a>1 and b>1.thats it
the following code gives an idea about for loop...............and this code generates the numbers from 1 to 10.
for i=1:10
disp(i);
end
so from the code we can say every for loop should have an end statement.............that end statement is end.
the if statement uses some logical operators for decision making........they r
&-and
|-or
~-negation
observe the following code for if statement..........
a=input('enter the value of a');
b=input('enter the value of b');
if((a>1)&(b>1))
for i=1:10
disp(i);
end
end
the code gives the output as the number from 1 to 10 if and only if a>1 and b>1.thats it
MATLAB-1
hi ,i m sudheer suraparaju.......studying mtech first year in nit durgapur........under the branch telecommunications.......this blog is a result of my endeavour for matlab..........i think to start matlab, some basic stuff is needed .........and i m starting my blog articles with a very basic stuff..........the basic functions that i m going to discuss in this article r
1.input
2.disp
as the name input suggests it is some function which takes input from the user..........so when the function input is used then the computer is able to ask the input from the user.........see the code bellow:
age=input('enter ur age');
here the input function accepts the age and it keep the value in the variable 'age'
if i want to see what is there inside this variable age.........then the function that outputs the value inside the age is 'disp'
so if i type disp(age);
then it gives the value inside the age.............thats it when i want to work with strings.............
name=input('enter ur name','s');
disp(name);
this will output the string inside the variable name.......thats it .............
that is when u want to work with strings.....just use 's'
just remember that for the arguments inside the input we should use ' ' but for the disp function there is no need to use those inverted commas.................
1.input
2.disp
as the name input suggests it is some function which takes input from the user..........so when the function input is used then the computer is able to ask the input from the user.........see the code bellow:
age=input('enter ur age');
here the input function accepts the age and it keep the value in the variable 'age'
if i want to see what is there inside this variable age.........then the function that outputs the value inside the age is 'disp'
so if i type disp(age);
then it gives the value inside the age.............thats it when i want to work with strings.............
name=input('enter ur name','s');
disp(name);
this will output the string inside the variable name.......thats it .............
that is when u want to work with strings.....just use 's'
just remember that for the arguments inside the input we should use ' ' but for the disp function there is no need to use those inverted commas.................
Subscribe to:
Posts (Atom)