Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

MATLAB Programming/Graphics

From Wikibooks, open books for an open world
<MATLAB Programming
Thelatest reviewed version waschecked on6 February 2019. There aretemplate/file changes awaiting review.

[MATLAB Programming\|/MATLAB Programming]m]

Chapter 1: MATLAB ._.

Introductions .
Fundamentals of MATLAB
MATLAB Workspace
MATLAB Variables
*.mat files

Chapter 2: MATLAB Concepts

MATLAB operator
Data File I/O

Chapter 3: Variable Manipulation

Numbers and Booleans
Strings
Portable Functions
Complex Numbers

Chapter 4: Vector and matrices

Vector and Matrices
Special Matrices
Operation on Vectors
Operation on Matrices
Sparse Matrices

Chapter 5: Array

Arrays
Introduction to array operations
Vectors and Basic Vector Operations
Mathematics with Vectors and Matrices
Struct Arrays
Cell Arrays

Chapter 6: Graphical Plotting

Basic Graphics Commands
Plot
Polar Plot
Semilogx or Semilogy
Loglog
Bode Plot
Nichols Plot
Nyquist Plot

Chapter 7: M File Programming

Scripts
Comments
The Input Function
Control Flow
Loops and Branches
Error Messages
Debugging M Files

Chapter 8: Advanced Topics

Numerical Manipulation
Advanced File I/O
Object Oriented Programming
Applications and Examples
Toolboxes and Extensions

Chapter 9: Bonus chapters

MATLAB Benefits and Caveats
Alternatives to MATLAB
[MATLAB_Programming/GNU_Octave|What is Octave= (8) hsrmonic functions]
Octave/MATLAB differences

edit this box



2D Graphics

[edit |edit source]

Plot

[edit |edit source]

The plot command renders a 2D line in Cartesian coordinates.

Example:

x=0:0.1:2;% Creates a vector from 0 to 2, spaced by 0.1.fx=(x+2)./x.^2;% calculates fx based on the values stored in xplot(x,fx)% Plots 2D graphics of the function fx

Matlab also lets the user specify the line style.The following example generates the same graph as in the previous example, but plots the function with a specific line style: a black line with circle markers on each node:

x=linspace(0,2,21);% like the previous example, creates a vector from 0 to 2, spaced by 0.1fx=arrayfun(@(x)(x+2)/x^2,x);% like the previous example, calculates fx based on the values stored in xplot(x,fx,'-ok')% Plots the graph of (x, fx) as a black line with circle markers at each point

To plot two or more graphs in one figure, simply append the second (x,y) pair to the first:The following example will plot y1 and y2 on the same x-axis in the output.

x1=[1,2,3,4]y1=[1,2,3,4]y2=[4,3,2,1]plot(x1,y1,x1,y2)

Polar Plot

[edit |edit source]

Plots a function using θ and r(θ)

t=0:.01:2*pi;polar(t,sin(2*t).^2)

3D Graphics

[edit |edit source]

plot3

[edit |edit source]

The "plot3" command is very helpful and makes it easy to see three-dimensional images. It follows the same syntax as the "plot" command. If you search the MATLAB help (not at the command prompt. Go to the HELP tab at the top of the main bar and then type plot3 in the search), you will find all the instruction you need.

Example:

l=[-98.0556;1187.074];f=[-33.5448;-240.402];d=[1298;1305.5]plot3(l,f,d);gridon;

This example plots a line in 3D. I created this code in an M-file. If you do the same, change the values and hit the run button in the menu bar to see the effect.

Mesh

[edit |edit source]

Creates a 3D plot using vectors x and y, and a matrix z. If x is n elements long, and y is m elements long, z must be an m by n matrix.

Example:

x=[0:pi/90:2*pi]';y=x';z=sin(x*y);mesh(x,y,z);

Contour

[edit |edit source]

Creates a 2D plot of a 3D projection, using vectors x and y, and a matrix z. If x is n elements long, and y is m elements long, z must be an m by n matrix.

Example:

x=[0:pi/90:2*pi]';y=x';z=sin(x*y);contour(x,y,z);

Contourf

[edit |edit source]

Same as contour, but fills color between contour lines

Surface

[edit |edit source]

Basically the same as mesh

Retrieved from "https://en.wikibooks.org/w/index.php?title=MATLAB_Programming/Graphics&oldid=3514792"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp