logo for matrixlab-examples.com
[?] Subscribe To This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Subscribe with Bloglines


Home
Matrixmania Blog
Contact
-> Sitemap <-
Matlab Books
Quick Matlab Guide
Matlab Tutorials
Matlab Examples
Matlab Flow Control
Boolean Algebra
Linear Algebra
Matlab 2D Plots
Matlab 3D Plots
Matlab GUI
Matlab Cookbook I
Matlab Cookbook II
Probability and Stats
Forums and Help
Relevant Links
Fun!
Your own Website?
Terms/Policies
leftimage for matrixlab-examples.com

Examples: MATLAB Plots



In this group of examples, we are going to create several MATLAB plots.



2D Cosine Plot
y=cos(x), for matlab plots 1 fig

You can type this in an 'm-file':

% Simple script to plot a cosine
% vector x takes only 10 values
x = linspace(0, 2*pi, 10);
y = cos(x);
plot(x,y)
xlabel('x')
ylabel('cos(x)')
title('Plotting a cosine')
grid on

The result is:
matlab plots 2 fig. 

If we use 100 points rather than 10, and evaluate two cycles instead of one (like this):

x = linspace(0, 4*pi, 100);

We obtain a different curve:
 
matlab plots 3 fig.


 
Now, a variation with line-syles and colors (type 'help plot' to see the options for line-types and colors):

clear; clc; close all;
% Simple script to plot a cosine
% vector x takes only 10 values
x = linspace(0, 4*pi, 100);
y = cos(x);
plot(x,y, 'ro')
xlabel('x (radians)')
ylabel('cos(x)')
title('Plotting a cosine')
grid on

 cosine red plot



Space curve

Use the command plot3(x,y,z) to plot the helix:

If  x(t)=sin(t), y(t)=cos(t), z(t)=(t) for every t in  t less than 10pi fig.,
then, you can type this code in an 'm-file' or in the command window:

% Another way to assign values to a vector
t = 0 : pi/50 : 10*pi;
plot3(sin(t),cos(t),t);

 helix fig.

You can use the 'help plot3' command to find out more details.



From 'Matlab Plots' to home
From 'Matlab Plots' to 'Matlab Examples'


footer for matlab plots page