본문으로 건너뛰기
Hub Nexus
업데이트됨

작성자아직 작성자가 없습니다맡기

개선할 점이 보이나요? 변경을 제안하세요.

후원

이 페이지는 공개 상태입니다.

2D Graphics

Plot

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 x
plot(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.1
fx= arrayfun(@(x) (x+2)/x^2, x); % like the previous example, calculates fx based on the values stored in x
plot(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

Plots a function using θ and r(θ)

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

3D Graphics

plot3

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); grid on;

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

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

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

Same as contour, but fills color between contour lines

Surface

Basically the same as mesh

Where this page came from

This page was imported from Wikibooks. From “MATLAB Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

이 페이지가 속한 매거진MATLAB Programming

언어English

이용 허락: CC BY-SA 4.0 · 출처 en.wikibooks.org

견해

코멘트

Spinner Logo
버전: 2CC0 1.0 (퍼블릭 도메인)
The runaway star that left the Tarantula Nebula
버전: 2CC0 1.0 (퍼블릭 도메인)
The Eagle Nebula, seen in the infrared
버전: 2CC0 1.0 (퍼블릭 도메인)
The Cosmic Cliffs are not cliffs
버전: 2CC0 1.0 (퍼블릭 도메인)
The recommended targets are real, but the largest health gain is between doing nothing and doing a little. That is the part worth knowing if you are starting from nothing.
버전: 2CC0 1.0 (퍼블릭 도메인)
Sleep is not one state but a cycle through several, each doing different work. Most sleep disorders are a failure to complete that cycle rather than a shortage of hours.
버전: 2CC0 1.0 (퍼블릭 도메인)
Four nebulae that revealed the shape of our galaxy