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 个)

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