How can I graph this matrix?

1 vue (au cours des 30 derniers jours)
Valeria Chacon
Valeria Chacon le 20 Nov 2016
Commenté : Nick Counts le 20 Nov 2016
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 commentaire
KSSV
KSSV le 20 Nov 2016
You want a surface plot or line plot?

Connectez-vous pour commenter.

Réponses (1)

Nick Counts
Nick Counts le 20 Nov 2016
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 commentaires
Nick Counts
Nick Counts le 20 Nov 2016
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 le 20 Nov 2016
Something like this?
theta = mod(bsxfun(@plus, (1:5), (1:5).'),2)
pcolor(theta)

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by