Showing posts with label Plots in Matlab. Show all posts
Showing posts with label Plots in Matlab. Show all posts

Saturday, June 11, 2011

3 D Plots in Matlab

3 D Plots in Matlab

To create 3D plots , first of all we need to create 3 variables. x,y and z.

Create the x and y  arrays:-
>> x=-3:0.25:3;
>> y=-3:0.25:3;

Create the meshgrid:-

>> [X Y]=meshgrid(x,y);


Define:-
Z=sqrt(X.^2 + Y.^2);

mesh(X,Y,Z);





>>surf(X,Y,Z);



>>surf(X,Y,-Z);





>>waterfall(X,Y,Z):-
 >>contour(x,y,z):
 >>>> surfc(X,Y,Z):-
 Now we arrive to the view part:
View is used to give the viewing angle of the plot. the syntax of the command is :-
view(azimuth,elevation);
where  the azimuth is an angle measured in degrees  in the x-y plane and is measured relative to the negative y axis and positive as always in the anti clockwise direction.

The elevation is the angle measured from the x-y plane in the direction of the z - axis.
default values are azimuth=-37.5 and elevation =35.
Here are the results of applying different views to the last plot:-

>> view(-65,30);

 >> view(-37.5,40);

Next we shall move to interpolation using Matlab.

Thursday, June 9, 2011

Simple Plots in Matlab

Simple Plots in Matlab

This is a continuation of the earlier post Matlab Basics
Creating Plots in Matlab is probably the easiest in all possible options present in the Software Universe. We shall study only the most basic methods in this Post and then advance to comparatively complex features.

Create a Vector for representing the X - Axis
>> x=[-2*pi:.001:2*pi];
>>
>> y=sin(x);
>> plot(x,y)
>> 




>> plot(cos(x),sin(x))
>>

 


 
>> plot(cos(x),sin(x).*cos(x))
>> 
%Remember the .* represents the dot product, and is necessary because all variables in Matlab are vectors and by default it will try to multiply them as matrices.


Next, we shall advance to more complex formatting of Plots, and then 3D plots.