フィルターのクリア

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 Center および File Exchange2-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