필터 지우기
필터 지우기

How can I graph this matrix?

조회 수: 1 (최근 30일)
Valeria Chacon
Valeria Chacon 2016년 11월 20일
댓글: Nick Counts 2016년 11월 20일
theta=zeros(N,N);
theta = mod(bsxfun(@plus, (1:N), (1:N).'),2);
x1=(R*cos(theta+Phase)/sqrt(2));
y1=(R*sin(theta+Phase)/sqrt(2));
plot(x1,y1);
fill(x1,y1,color1);
hold;
How can I graph the matrix "theta"? This is the x and y I should use but for some reason it just gives me a slanted line. In this case, N, R, and color1 are inputed by the user and the phase is pi/4. Thank you!
  댓글 수: 1
KSSV
KSSV 2016년 11월 20일
You want a surface plot or line plot?

댓글을 달려면 로그인하십시오.

답변 (1개)

Nick Counts
Nick Counts 2016년 11월 20일
As KSSV said, we need to know what you mean by "graph the matrix."
Your code will definitely make a line, though. From the documentation for plot()
plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, disconnected
line objects are created and plotted as discrete points vertically at
X.
Since you passed two matrixes, plot goes element by element (I believe down each column, successively).
Now, look at what kind of x1 and y1 you are creating. They are simply alternating between two values.
>> y1=(sin(theta)/sqrt(2))
y1 =
0 0.5950 0 0.5950 0
0.5950 0 0.5950 0 0.5950
0 0.5950 0 0.5950 0
0.5950 0 0.5950 0 0.5950
0 0.5950 0 0.5950 0
That means when plot() works its way through the matrixes, it is plotting like this:
>> [x1(1:10)', y1(1:10)']
ans =
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
So plot() is just drawing a line back and forth between those two points over and over :)
  댓글 수: 3
Nick Counts
Nick Counts 2016년 11월 20일
So what do your x1, y1, and theta values correspond to?
You will probably need need to establish the coordinates of each square. Currently, x1 and y1 are not doing that :)
Nick Counts
Nick Counts 2016년 11월 20일
Something like this?
theta = mod(bsxfun(@plus, (1:5), (1:5).'),2)
pcolor(theta)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by